use*_*848 10 jquery scroll smooth-scrolling
我有一个链接,可以在滚动时更改其垂直位置.当我点击此链接时,我想在我的页面上找到某个位置(平滑),该链接位于距页面顶部正好1080px的位置.
我不能让它工作,希望有人可以帮助我.
链接:
<img src="img/clickme.png" style="cursor: pointer;" class="scroll"/>
Run Code Online (Sandbox Code Playgroud)
剧本:
<script type="text/javascript">
$(document).ready(function() {
$(".scroll").click(function(event){
$('html, body').animate({scrollTo({ top: '+1080px',}, 800);
});
});
</script>
Run Code Online (Sandbox Code Playgroud)
Ble*_*der 22
试试这个.你的语法有点偏差:
$(document).ready(function() {
$(".scroll").click(function(event){
$('html, body').animate({scrollTop: '+=1080px'}, 800);
});
});
Run Code Online (Sandbox Code Playgroud)
演示:http://jsfiddle.net/m4Aaz/2/