Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery: Auto scroll to top

i use this script to open a modal:

    <script type="text/javascript">
$(function(){
$('.compose').click(function() { 
    $('#popup_bestanden_edit_name').reveal({ 

        animation: 'fade',  
        animationspeed: 600,  
        closeonbackgroundclick: true,  
        dismissModalClass: 'close',
            });
    return false;
});
}); </script>

But when i'm at the bottom of the page and click the link, the modal opens at the top of the page. So it looks like nothing happends, but i have to scroll to the top to see the modal opened.

Is it possible to send the user automatically to the top when the modal is opened?

like image 471
Rick A. Avatar asked Dec 08 '22 12:12

Rick A.


1 Answers

use below code to move to top of page:

$('html, body').animate({scrollTop: '0px'}, 0);

Instead of 0, you can have some other value like 500 (its in milliseconds) to make it move to top slowly

like image 139
Rajesh Avatar answered Dec 11 '22 00:12

Rajesh