jQuery Window Scroll code formatting issue

jQuery Window Scroll code formatting issue

Hi there!

I'm a newbie with writing jQuery on my own and I'm running into a snag with having jQuery add a class once the window has scrolled down after a set amount of pixels.

The navbar currently has some code that toggles classes to create a fade effect to make the navbar appear 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 in WordPress with a custom .js functions file - here is the code that works so far for the fade effect and a slider:

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");

});
});


Here's what worked from another site to make the navbar fixed after scrolling down the page:

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! :)