Mohsen Golestan
Mohsen Golestan

Reputation: 1

using jquery function to wordpress theme

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

Upvotes: 0

Views: 49

Answers (3)

Mohsen Golestan
Mohsen Golestan

Reputation: 1

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

Upvotes: 0

RipzCurlz
RipzCurlz

Reputation: 507

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

Upvotes: 0

manian
manian

Reputation: 1438

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

Upvotes: 1

Related Questions