开发者

How can I use Simple Modal to scroll to the top of my page just before the modal launches?

开发者 https://www.devze.com 2023-01-18 12:39 出处:网络
I\'m successfully using Simple Modal to launch a modal when a button is clicked, however, I want the page to scroll to the top first.I tried placing an anchor tag at the top of the page and referencin

I'm successfully using Simple Modal to launch a modal when a button is clicked, however, I want the page to scroll to the top first. I tried placing an anchor tag at the top of the page and referencing it in my link using , but it didn't work. The Simple Modal still worked, but it didn't scroll to the top of t开发者_C百科he page first. Is there a way to edit the simple modal javascript to make it first scroll to the top of the page before the modal is opened?


use JavaScript before you call your modal: window.scrollTo(0,0)


Use a callback: http://www.ericmmartin.com/projects/simplemodal/#options

$('#modalContent').modal({
    onOpen: function () {
        $('html, body').scrollTo(0, 0);
    }
});
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号