JavaScript jQuery Window Scroll code formatting issue jquery window scroll position,jquery window scroll function,jquery window

newbie: writing jQuery on my own

So I'm running into a snag with having jQuery add a class once the window has scrolled down after a set amount of pixels.

To set a little background, the navbar currently has some jQuery that toggles classes to create a little fade effect when clicked. It's static and sits down a little ways on the page. My problem is adding the jQuery that continues to add classes as the window is scrolled down to basically add the class that will make the navbar fixed to the top of the page once the static nav is out of view.

I'm creating a child theme with a custom .js functions file - here is the code that works so far:

    jQuery(document).ready(function($) {   
    $('.testimonials').bxSlider();

   $('.home .siteBrand').click(function(){
        $('.home .x-navbar').toggleClass("x-navbarOpen");
        $('.home .x-navbar').addClass("ani");
        $('.home .x-nav-wrap.desktop').toggleClass("siteBrandOpen");
        $('.home .x-nav-wrap.desktop').addClass("ani");
        $('.home .x-navbar .desktop .x-nav > li > a').toggleClass("menuOpen");
        $('.home .x-navbar .desktop .x-nav > li > a').addClass("ani");

    });
});

The following code is what worked from another site:

var $j = jQuery.noConflict();   

$j(window).scroll(function() {    
    var scroll = $j(window).scrollTop();

    if (scroll >= 750) {
        $j(".home .x-navbar").addClass("x-navbar-fixed-top");
    } else {
        $j(".home .x-navbar").removeClass("x-navbar-fixed-top");
    }
});

It only works when adding the code to the Custom Javascript feature of the theme, but I need this to all be in the child theme's custom .js file and after much playing with the code, I'm not sure how to format this snippet to make it work within the custom file. One of the issues I noticed is regardless if I add the window scroll code in the theme feature or try to play around with it in the custom file, the code that did work in the custom file stops.

Can anyone tell me what I'm doing wrong? Thank you! :)

Answer:1

I am working to get response from SOLR using jquery. When I use the below code I got the error saying Typeerror:data is null When looked at the code in firebug, data in on_data function is null. I ...

I am working to get response from SOLR using jquery. When I use the below code I got the error saying Typeerror:data is null When looked at the code in firebug, data in on_data function is null. I ...

  1. retrieve results from multiple google pages
  2. retrieve results from mysql
  3. unable to retrieve results from nuget.org
  4. results from retrieve cream

Basically I want to be able to select the div level2 parent from the child level4 div. My application does not has such classes, otherwise I'd just select level2 :) <div class="level1"> <...

Basically I want to be able to select the div level2 parent from the child level4 div. My application does not has such classes, otherwise I'd just select level2 :) <div class="level1"> <...

  1. jquery select child element
  2. jquery select child by class
  3. jquery select child of this
  4. jquery select child of id
  5. jquery select child of parent
  6. jquery select child input
  7. jquery select child by index
  8. jquery select child of div
  9. jquery select child of element with class
  10. jquery selector child of sibling
  11. jquery select child span
  12. jquery select child class of parent
  13. jquery select child element by tag
  14. jquery select child element with specific class
  15. jquery select child by tag
  16. jquery select child by name
  17. jquery select child element of parent
  18. jquery select child element by name
  19. jquery select child button
  20. jquery select child by type

The help that I received from other users on this forum didn't help at all ... I have a chart that is generated through google charts API on this link http://imageshack.us/f/9/capturesfn.png/ ...

The help that I received from other users on this forum didn't help at all ... I have a chart that is generated through google charts API on this link http://imageshack.us/f/9/capturesfn.png/ ...

I am using sails.js to create a tag system that has many-to-many relations with an entity called Post. The way I am doing the association is to use a database table to correlate each tagId with the ...

I am using sails.js to create a tag system that has many-to-many relations with an entity called Post. The way I am doing the association is to use a database table to correlate each tagId with the ...

  1. using lib async