1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Jquery, struggling to adapt scroling code

Discussion in 'jQuery' started by smrdo, Jun 5, 2014.

  1. #1
    Hi,
    I have the jquery below which is being used in a worpdres theme, to control one page scrolling.
    I'd like to adapt it to meet the following condition only AFTER the page has scrolled..

    if #id1 a OR #id2 a ="active" remove the class "active" from #id3

    Hope this makes sense, many thanks for any help.

    the jquery scrolling code is
    /*-----------------------------------------------------------------------------------*/
    /*    SCROLL EFFECTS & HEADER
    /*-----------------------------------------------------------------------------------*/
    jQuery(window).load(function($){
    'use strict';
    
        /**
         * Page Loaded Stuff
         */
        jQuery('#page-loader').addClass('animated fadeOutDown');
        jQuery('body, html').addClass('window-loaded');
        jQuery('.light.scroller').animate({ 'opacity' : '1' });
       
        /**
         * Scroll Animations
         */
        jQuery('.animated').espy(function (entered, state) {
            var $this = jQuery(this);
            if (entered){
                $this.addClass( $this.attr('data-animation') );
            }
        });
       
        // Bind the event.
        jQuery(window).hashchange( function(){
            var url = location.hash;
            var minus = 64;
            if( jQuery('body').hasClass('admin-bar') )
                var minus = 96;
           
            if( url )
                jQuery("html, body").animate({ scrollTop: jQuery(url).offset().top - minus }, 500);
        });
       
        // Trigger the event (useful on page load).
        jQuery(window).hashchange();
       
        jQuery('#selectnav .scroller > a').click(function(){
            var $this = jQuery(this);
            jQuery('#selectnav .scroller').removeClass('active');
            $this.parent().addClass('active');
            jQuery('#selectnav .scroller a').removeClass('active');
            $this.addClass('active');
            history.pushState(null, null, $this.attr('href'));
            jQuery(window).hashchange();
            return false;
        });
       
        jQuery('a.scroller').click(function(){
            history.pushState(null, null, jQuery(this).attr('href'));
            jQuery(window).hashchange();
            return false;
        });
       
        jQuery(window).scroll(function(){
    
            var scrollTop = jQuery(window).scrollTop() / 12;
            var $header = jQuery('header#main-header');
            var $sub = jQuery('#selectnav ul');
           
            if( scrollTop < 20 ){
                $header.css({
                    'padding-top' : 25 - scrollTop,
                    'padding-bottom' : 25 - scrollTop
                });
                $sub.css({
                    'padding-top' : 42 - scrollTop
                });
            } else {
                $header.css({
                    'padding-top' : 5,
                    'padding-bottom' : 5
                });
                $sub.css({
                    'padding-top' : 22
                });
            }
           
            jQuery('#selectnav .scroller > a').each(function(){
                var scrollHref = jQuery(this).attr('href');
                if( jQuery(scrollHref).length > 0 ){
                    if( jQuery(window).scrollTop() > jQuery(scrollHref).offset().top - 240 ) {
                        jQuery('#selectnav .scroller').removeClass('active');
                        jQuery(this).parent().addClass('active');
                       
                    }
                }
            });
           
        });
    
    });
    Code (JavaScript):
     
    smrdo, Jun 5, 2014 IP
  2. ThePHPMaster

    ThePHPMaster Well-Known Member

    Messages:
    737
    Likes Received:
    52
    Best Answers:
    33
    Trophy Points:
    150
    #2
    Use hasClass/removeClass:

    
    if (($('#id1').hasClass('active') || $('#id2').hasClass('active')) && $('#id3').hasClass('active') {
        $('#id3').removeClass('active');
    }
    
    Code (markup):
     
    ThePHPMaster, Jul 5, 2014 IP