2013-11-09 8 views

risposta

20

Prova questa

$("#button").on('click',function() { 
    $('html, body').animate({ 
     'scrollTop' : $("#dynamictabstrp").position().top 
    }); 
}); 

.scrollTop()

8

Prova

.scrollTop()

$(window).scrollTop($('#dynamictabstrp').offset().top); 


o

scrollIntoView()

$('#dynamictabstrp')[0].scrollIntoView(true); 

o

document.getElementById('dynamictabstrp').scrollIntoView(true); 
1

Ecco il codice: -

$(document).ready(function(){ 
    $("#button").on('click',function(){     
     $('html, body').animate({ 
       scrollTop: $("#dynamictabstrp").offset().top 
     }, 1000);    
    }); 
}); 

o

$(document).ready(function(){ 
    $("#button").click(function(){     
     $('html, body').animate({ 
       scrollTop: $("#dynamictabstrp").offset().top 
     }, 1000);    
    }); 
}); 
0

Tr y questo semplice script. Cambia #targetDiv con il tuo particolare ID div o Classe.

$('html,body').animate({ 
    scrollTop: $('#targetDiv').offset().top 
}, 1000); 

Il codice sorgente e demo live si possono trovare da qui - Smooth scroll to div using jQuery

0

è possibile impostare compensato secondo il requisito

jQuery(document).ready(function(){ 
function secOffset(){ 
         jQuery('html, body').animate({ 
         scrollTop: jQuery(window.location.hash).offset().top - 60 
       }, 0); 
     } 
}); 
Problemi correlati