Extra JS script loads but doesn't work
-
OK – correction to my previous post. Here’s the current problem now:
I have a js script that I want to load to the page. If I hard-code it onto the <head> section of header.php (including loading an external minified jquery, http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js ) it works just fine.
However, if I remove the link to the external jquery file, it stops working.
If I try to load the script through wp_enqueue (functions.php), it loads just fine (I can see it loaded on <head>, and if I click on the link it opens the file, so it links to the correct file), but it still doesn’t work.
What could be the problem?
Here is the original script:
$(function() { $(window).on('scroll', function() { $('#par_background').css('margin-top', $(window).scrollTop() * -.3); }); }); $(document).ready(function () { $(window).bind('scroll', function () { var distance = 50; if ($(window).scrollTop() > distance) { $('nav').addClass('scrolled'); } else { $('nav').removeClass('scrolled'); } }); });And here’s the modified content of test.js file, formatted to load with wp_enqueue (but I am not confident at all if this is the correct formatting, not an expert with JS):
jQuery(function() { $(window).on('scroll', function() { $('#par_background').css('margin-top', $(window).scrollTop() * -.3); }); }); jQuery(function () { $(window).bind('scroll', function () { var distance = 50; if ($(window).scrollTop() > distance) { $('nav').addClass('scrolled'); } else { $('nav').removeClass('scrolled'); } }); });Any help would be appreciated!
The topic ‘Extra JS script loads but doesn't work’ is closed to new replies.