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
Can you please replace '$' with jQuery everywhere in the above is code and try again
answered Mar 23, 2017 at 20:13
manian
1,4482 gold badges18 silver badges34 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
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");
}
});
});
answered Mar 23, 2017 at 20:22
RipzCurlz
5172 gold badges5 silver badges16 bronze badges
1 Comment
RipzCurlz
Have you tried putting a console log in the scroll function to test if it is firing on the scroll event?
oh, I found that
I deleted the script version and then it worked
Comments
Explore related questions
See similar questions with these tags.
default