如何向下滚动 - JQuery

use*_*037 18 javascript jquery

我不是程序员,但我使用下面的代码将页面滚动到顶部.

如何调整它以向下滚动?

<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>
Run Code Online (Sandbox Code Playgroud)

und*_*ned 52

$('.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
});
Run Code Online (Sandbox Code Playgroud)


小智 15

试试这个:

window.scrollBy(0,180); // horizontal and vertical scroll increments
Run Code Online (Sandbox Code Playgroud)

  • OP可能假设需要jQuery.这个答案可能会有所帮助. (19认同)
  • OP 提到了 **jQuery** 解决方案。 (2认同)

Aza*_*lvi 8

这可以用来解决这个问题

<div id='scrol'></div> 
Run Code Online (Sandbox Code Playgroud)

在JavaScript中使用此

jQuery("div#scrol").scrollTop(jQuery("div#scrol")[0].scrollHeight);
Run Code Online (Sandbox Code Playgroud)


Mud*_*Ali 8

我主要使用以下代码向下滚动

$('html, body').animate({ scrollTop:  $(SELECTOR).offset().top - 50 }, 'slow');
Run Code Online (Sandbox Code Playgroud)