简体   繁体   English

.click事件在主页上有效,但不起作用并在后页上工作

[英].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. 经过多次测试后,我控制两个页面中是否有不同的地方,但是否有相同的Js,相同的插件。

I don't understand what is the problem. 我不明白是什么问题。

Please help me. 请帮我。

You're using event.preventDefault() - event is not defined, e is. 您正在使用event.preventDefault() -未定义evente是。 Change it to e , instead of event , and it'll probably work. 将其更改为e ,而不是event ,它可能会起作用。 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. 那可能不是错误,但是它将阻止脚本的其余部分运行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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