使用jQuery单击时垂直滚动100%

时间:2014-10-28 08:30:14

标签: javascript jquery scroll

我需要一个动画滚动效果,将网站压缩100%。它基本上是一个网站的多页,每个100%,有一个不同的网站。我知道有多个插件,但我想让它手动工作。

我尝试使用锚点和ID来激发100%滚动效果,但我想不出一个纯粹的解决方案,在没有其他ID或类的某种帮助的情况下将页面向下移动100%。

任何帮助都将受到高度赞赏。

1 个答案:

答案 0 :(得分:3)

嗯,非常简单,使用下面的代码片段,它将帮助您实现您想要的...

$("a").on("click", function(event) {
    event.preventDefault(); //Prevent default action of anchor
    $("html, body").animate({ 
        scrollTop: $(document).height()  //Get the document height
    }, "slow"); //Animates the scroll
    /* Can also use 3000, 4000 i.e 3 seconds, 4 seconds to animate the scroll */
});

此处onclick标记的<a>,我们首先阻止锚标记的默认操作,然后点击,我们将滚动设置为文档底部的动画。

Demo

注意:使用idclass作为您希望附加onclick evebt的锚标记,因为当前使用的选择器是普通选择器并且将定位所有文档中的锚标记。