简体   繁体   中英

.click event work on home page but didn't work and post page


I try to solved this problem but I don't understood where is the error.

I have and footer of all pages a to the visitors can comeback to the important part of the site whit slow animation.

In main page any problem that work correctly.

But in post page the animation didn't existe. this is an exemple of page with the problem.

the code I used for the animation is this:

 $(".gotof").click(function (e) {
    var b = $(this).attr("href").substr(1);
 console.log(b);
event.preventDefault();
        $(".wrapper").animate({
        scrollTop: $("#" + b).offset().top + $(".wrapper").scrollTop()-60 
    }, "slow");
 console.log('e');});  

First I think is the sibling of the element but no problem in this part.
After I try other functions for scroll to an anchor.
After multiples tests I control if something is not same in the two page but same Js, same plugin.

I don't understand what is the problem.

Please help me.

You're using event.preventDefault() - event is not defined, e is. Change it to e , instead of event , and it'll probably work. If you had looked in the browser console, you'd seen this. That might not be the error, but it will prevent the rest of the script to run.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM