Javascript 如何向下滚动 - JQuery
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12650170/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to Scroll Down - JQuery
提问by user1301037
I'm not a programmer, but I use the code below to scroll the page to the top.
我不是程序员,但我使用下面的代码将页面滚动到顶部。
How can I adapt it to make a scroll down?
我怎样才能使它向下滚动?
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
<a class="btnMedio" href="javascript:;">
<img src="http://desmond.imageshack.us/Himg41/scaled.php?server=41&filename=deixeseuemail.png&res=landing"/>
</a>
<script>
$('.btnMedio').click(function(){
$('html, body').animate({scrollTop:1000},'50');
});
</script>
回答by undefined
$('.btnMedio').click(function(event) {
// Preventing default action of the event
event.preventDefault();
// Getting the height of the document
var n = $(document).height();
$('html, body').animate({ scrollTop: n }, 50);
// | |
// | --- duration (milliseconds)
// ---- distance from the top
});
回答by Ryhan
Try This:
尝试这个:
window.scrollBy(0,180); // horizontal and vertical scroll increments
回答by Azam Alvi
This can be used in to solve this problem
这可以用来解决这个问题
<div id='scrol'></div>
in javascript use this
在javascript中使用这个
jQuery("div#scrol").scrollTop(jQuery("div#scrol")[0].scrollHeight);
回答by Mudaser Ali
I mostly use following code to scroll down
我主要使用以下代码向下滚动
$('html, body').animate({ scrollTop: $(SELECTOR).offset().top - 50 }, 'slow');
回答by Isuru Dinusha
If you want to scroll down to the div (id="div1"). Then you can use this code.
如果你想向下滚动到 div (id="div1")。然后你可以使用这个代码。
$('html, body').animate({
scrollTop: $("#div1").offset().top
}, 1500);
回答by KhaLed El-Fishawy
jQuery(function ($) {
$('li#linkss').find('a').on('click', function (e) {
var
link_href = $(this).attr('href')
, $linkElem = $(link_href)
, $linkElem_scroll = $linkElem.get(0) && $linkElem.position().top - 115;
$('html, body')
.animate({
scrollTop: $linkElem_scroll
}, 'slow');
e.preventDefault();
});
});