簡體   English   中英

如何向下滾動-jQuery

[英]How to Scroll Down - 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>
$('.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
});

嘗試這個:

window.scrollBy(0,180); // horizontal and vertical scroll increments

這可以用來解決這個問題

<div id='scrol'></div> 

在javascript中使用此

jQuery("div#scrol").scrollTop(jQuery("div#scrol")[0].scrollHeight);

我主要使用以下代碼向下滾動

$('html, body').animate({ scrollTop:  $(SELECTOR).offset().top - 50 }, 'slow');
    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();
        });
    });

如果要向下滾動到div(id =“ div1”)。 然后,您可以使用此代碼。

 $('html, body').animate({
     scrollTop: $("#div1").offset().top
 }, 1500);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM