Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
94
rated 0 times [  101] [ 7]  / answers: 1 / hits: 30912  / 11 Years ago, mon, september 30, 2013, 12:00:00

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?


More From » jquery

 Answers
8

You can add position: fixed and for example top: 30px to styles for #popup_bestanden_edit_name. If you do that, modal will appear always in the same place, no matter where the user is on the page. But then you must be careful, because if modal is higher than viewport, you won't be able to see the remaining part of modal.



If you still want to scroll to top (without animation), using JavaScript you can put



$('body').scrollTop(0);


right before your return false;



BTW, if you want to prevent default action of a link to fire, it's a better practice to do it that way:



$('.compose').click(function(event) {
// your code here
event.preventDefault();
}

[#75345] Saturday, September 28, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
zahrafrancisr

Total Points: 176
Total Questions: 105
Total Answers: 99

Location: Svalbard and Jan Mayen
Member since Sun, Sep 25, 2022
2 Years ago
;