$(“html”)。animate({scrollTop:$(document).height()},“slow”); 如果它在底部不滚动它
我有三个隐藏div的按钮,当我点击一个我希望内容滚动到底部,然后当我点击另一个我希望页面保持原样但加载新内容。
我已经尝试过变量和if语句
var i=0; $('#link-slide13').click(function(){ if (i==0){//nothing's been scrolled $("html").animate({ scrollTop: $(document).height() }, "slow"); i=1; }else{ //don't do anything } });
有任何想法吗? 谢谢你的答案!
编辑:对不起,我真的不认为我已经解释过自己, http://ephemurl.com/4w/5ws在这里,是我现在所拥有的,最后6个部分反弹滚动到文档的底部,但我希望这只发生一次然后接下来的5次点击不会动画,因为你已经在那里……
只需使用$(body)代替$(html)
演示http://jsfiddle.net/APebY/
$(function(){ var i=0; $('#link-slide13').click(function(){ if (i==0){//nothing's been scrolled $("body").animate({ scrollTop: $(document).height() }, "slow"); i=1; }else{ //don't do anything } }); });
您还可以在事件触发器中使用unbind使其仅运行一次
$('#link-slide13').click(function(){ $("body").animate({ scrollTop: $(document).height() }, "slow"); $(this).unbind("click"); });
不知道你究竟想做什么,我猜这应该对你有帮助,
$('#link-slide13').toggle(function(){ $("html").animate({ scrollTop: $(document).height() }, "slow"); },function(){ //don't do anything })
祝好运