2012-09-29 55 views
16

No soy un programador, pero utilizo el siguiente código para desplazar la página hacia arriba.Cómo desplazarse hacia abajo - JQuery

¿Cómo puedo adaptarlo para hacer un desplazamiento hacia abajo?

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

Respuesta

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

Gracias por ayudar a ¿Cómo puedo limitar la distancia que la página vaya hacia abajo? – user1301037

+0

@ user1301037 Puede reemplazar 'n' con el valor que desee, también puede usar el método' offset'. – undefined

+0

Wow, has hecho mi día. –

13

intenta esto:

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

El OP ha mencionado una solución ** jQuery **. – crmpicco

+14

El OP puede suponer que se necesita jQuery para esto. Esta respuesta podría ser útil. –

4

Esto se puede utilizar para resolver este problema

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

en javascript uso de este

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

mayoría utilizo siguiente código para desplazarse hacia abajo

$('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

¿Podría explicar un poco su respuesta? – Eria

Cuestiones relacionadas