2012-09-29 26 views
16

Non sono un programmatore, ma uso il codice qui sotto per far scorrere la pagina verso l'alto.Come scorrere verso il basso - JQuery

Come posso adattarlo per far scorrere verso il basso?

<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> 

risposta

42
$('.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 
}); 
+0

Grazie per l'aiuto Come posso controllare de distanza che la pagina va giù? – user1301037

+0

@ user1301037 Puoi sostituire 'n' con qualsiasi valore tu voglia, puoi anche usare il metodo' offset'. – undefined

+0

Wow hai fatto la mia giornata. –

13

Try This:

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

L'OP ha menzionato una soluzione ** jQuery **. – crmpicco

+14

L'OP può presumere che jQuery sia necessario per questo. Questa risposta potrebbe essere utile. –

4

Questo può essere usato per risolvere questo problema

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

in javascript uso questo

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

Io uso soprattutto seguente codice per scorrere verso il basso

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

Potresti spiegare un po 'la tua risposta? – Eria

Problemi correlati