Lae*_*Lae 4 html css jquery scroll button
我正在制作一个网站,但是使用jQuery将页面向下滚动100%的按钮有问题.我遇到了麻烦,因为它在浏览器和窗口大小之间滚动不同的空格.我问题的任何解决方案?顺便说一句,这是我的代码......
jQuery的
var screenheight100 = css('height', '100%');
$('#gdb1').click(function(){
$("html, body").animate({ scrollTop: (screenheight100)}, 600);
return false;
});
Run Code Online (Sandbox Code Playgroud)
HTML
<div class="gdbox"><div id="gdb1" class="gdbutton fontwhitenshadow">Q</div></div>
Run Code Online (Sandbox Code Playgroud)
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;
}
Run Code Online (Sandbox Code Playgroud)
Has*_*ami 11
我假设您要实现的是将窗口滚动为窗口高度.
但css()它不是一个全局函数,它是一个jQuery对象方法.
你可以通过.height()方法获得窗口的高度:
$('#gdb1').click(function(){
$("html, body").animate({ scrollTop: $(window).height()}, 600);
return false;
});
Run Code Online (Sandbox Code Playgroud)
但是如果要在元素顶部滚动窗口,可以获得所需的空间$(selector).offset().top.