jQuery的动画滚动锚不工作? [英] jQuery animated scroll to anchor not working?

查看:150
本文介绍了jQuery的动画滚动锚不工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想我已经解决了这个问题,但事实证明,我没有。基本上建立一个tumblr主题,东西在我的code与jQuery的动画滚动到顶部冲突。我试着去掉事情我不能完全肯定它可能是什么,并认为这可能是真的很明显给他人?

I thought I had resolved this issue but turns out i hadn't. Basically building a tumblr theme and something in my code is conflicting with the jquery animated scroll to top. I've tried removing things as I'm not entirely sure what it could be and thought it might be really obvious to somebody else?

下面是我的主题 http://minori-theme.tumblr.com/ 链接而我是为了遵循的jsfiddle动画的平滑滚动 http://jsfiddle.net/YtJcL/1008/

Here is a link to my theme http://minori-theme.tumblr.com/ and a jsfiddle that I was following in order to animate the smooth scroll http://jsfiddle.net/YtJcL/1008/

在code我使用的是下面,我只使用一个标准的链接和ID它去正确的点这些链接的罚款只是不平滑滚动。

The code I'm using is below and I'm just using a standard a link and id which are linking fine as it goes to the correct point its just not smooth scrolling.

$(document).ready(function() {
var hashTagActive = "";
$(".scroll").click(function (event) {
    if(hashTagActive != this.hash) { //this will prevent if the user click several times the same link to freeze the scroll.
        event.preventDefault();
        //calculate destination place
        var dest = 0;
        if ($(this.hash).offset().top > $(document).height() - $(window).height()) {
            dest = $(document).height() - $(window).height();
        } else {
            dest = $(this.hash).offset().top;
        }
        //go to destination
        $('html,body').animate({
            scrollTop: dest
        }, 2000, 'swing');
        hashTagActive = this.hash;
    }
});
});

编辑:如果任何人有一个更简单的选择,我接受的建议?

If anyone has a simpler alternative I'm open to suggestions?

推荐答案

的涡旋工作的第一次,而不是之后的任何时间。检查通过习惯,看看有什么东西正在不停的所有变种的。

The scroll works the first time, but not any time after that. Check through all the var's that get used to see if something is being kept.

编辑:

if(hashTagActive != this.hash)

将不会与jQuery的动画麻烦,如果你已经点击返回顶部,因为hashTagActive已经#top返回。这就是为什么它的工作一次,但不是两次。

will not bother with the jquery animation if you have already clicked "Back to top" because the hashTagActive is already #top. Thats why it works once but not twice.

编辑2:
请查看这拨弄以变通的办法

这篇关于jQuery的动画滚动锚不工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆