简体   繁体   English

jQuery scrollTo插件不起作用

[英]jQuery scrollTo plugin not working

I'm using version 1.4.13 of the plugin, I've also made sure that the page has loaded the plugin successfully. 我正在使用该插件的1.4.13版,还确保该页面已成功加载该插件。

It used to work fine on my website but now it appears to be doing nothing. 它曾经在我的网站上运行良好,但现在似乎什么也没做。 I am using the following code to run it: 我正在使用以下代码运行它:

HTML: HTML:

<span class="button-project-info">
    <a class="button button-04" href="#project-info">Project Info</a>
</span>

CSS: CSS:

$('.button-project-info a').bind('click', function(e) {
    try {
        e.preventDefault();
        target = this.hash;
        $('html, body').scrollTo(target, 150);
    } catch (error) {
        alert('error - ' + error);
    }
});

I've also tried the following, and the alert statement runs fine when the link is clicked: 我也尝试了以下方法,并且单击链接时, alert语句运行良好:

$('.button-project-info a').bind('click', function(e) {
    alert('0000');
});

If you want to scroll the whole page, use: 如果要滚动整个页面,请使用:

    target = this.hash;
    $(window).scrollTo(target, 150);

I tend to use the href from the anchor when I do this, so instead of target = this.hash; 在执行此操作时,我倾向于使用锚中的href ,因此不是target = this.hash; I grab the hash from the link. 我从链接中获取哈希值。

Here is my preferred implementation, which basically catches all hash-URLs and scrolls... 这是我的首选实现,基本上可以捕获所有哈希URL和滚动...

$('.button-project-info a').click(function () {
  var hash = '#' + this.href.split('#')[1];
  $(window).scrollTo(hash, 1000);
  return false;
});

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

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