用于向页面滚动100%的jQuery向下滚动按钮

时间:2014-01-19 18:51:26

标签: jquery html css button scroll

我正在创建一个网站,但是使用jQuery将页面向下滚动100%的按钮有问题。我遇到了麻烦,因为它在浏览器和窗口大小之间滚动不同的空格。我问题的任何解决方案?顺便说一句,这是我的代码...

的jQuery

var screenheight100 = css('height', '100%');
$('#gdb1').click(function(){
    $("html, body").animate({ scrollTop: (screenheight100)}, 600);
    return false;
 });

HTML

<div class="gdbox"><div id="gdb1" class="gdbutton fontwhitenshadow">Q</div></div>

CSS

.gdbox{width: 100%;
       height: 35px;
       position: absolute;
       bottom: 30px; 
       text-align: center;
       overflow: visible;
}
.gdbutton{margin: 0 auto;
          height: 20px;
          padding-bottom: 20px;
          text-align: center;
          width: 40px;
          font-family: iconFont;
          font-size: 45px;
          cursor: pointer;
}

2 个答案:

答案 0 :(得分:11)

我假设您想要实现的是将窗口滚动为窗口高度。

但是css()不是全局函数,它是一个jQuery对象方法。

你可以通过.height()方法得到窗口的高度:

$('#gdb1').click(function(){
    $("html, body").animate({ scrollTop: $(window).height()}, 600);
    return false;
});

<强> Working Fiddle

但是如果你想在元素顶部滚动窗口,你可以通过$(selector).offset().top获得所需的空间。

答案 1 :(得分:0)

您可以在页面上放置一个隐藏元素,并始终滚动到该元素的顶部。这将使您在浏览器中更加一致。