0

Hi
i have a problem with using jquery in my wordpress theme.
it's code use to fixing a element after some scrolling
this is the jquery

jQuery(document).scroll(function($) {
var y = $(document).scrollTop(), //get page y value 
    header = $("#aside"); // your div id
if(y >= 305)  {
    header.css({position: "fixed", "top" : "0", "left" : "0"});
} else {
    header.css("position", "static");
}
});


and i use this code to add the file to wordpress theme in function.php

function website_scripts () {
wp_enqueue_script('aside_scroll', get_template_directory_uri().'/js/aside_scroll.js', array('jquery'), '1.0.0', true); }
add_action ('wp_enqueue_scripts', 'website_scripts');


but it's not working in wordpress however it works in html file

3 Answers 3

1

Can you please replace '$' with jQuery everywhere in the above is code and try again

Sign up to request clarification or add additional context in comments.

Comments

0

Try changing your js to this:

jQuery(document).ready(function($) {

     $(document).scroll(function() {
     var y = $(document).scrollTop(), //get page y value 
         header = $("#aside"); // your div id
     if(y >= 305)  {
         header.css({position: "fixed", "top" : "0", "left" : "0"});
     } else {
         header.css("position", "static");
     }
     });
});

1 Comment

Have you tried putting a console log in the scroll function to test if it is firing on the scroll event?
0

oh, I found that
I deleted the script version and then it worked

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.