简体   繁体   中英

Scroll modal to top after clicking navigation

i have the following code which loads wordpress posts into a modal which works great. The only problem is that when one of the nav links are clicked it loads the next post without scrolling to the top.

Is there any way i can make the modal scroll to the top when one of the nav links are clicked ?

(function($) {
$(document).ready(function($){
    $(document).on("click", ".esg-grid a, .postmodal .post-navigation a", function(event) {
             event.preventDefault();
        var post_url = $(this).attr("href");
        var post_id = $(this).attr("rel");
                $(".postmodal").load(post_url + " #main-content" );
                $(".postmodal-container").removeClass("hidden");
                //window.history.pushState("object or string", "Title", "/new-url");
    return false;
    });
});
})(jQuery);

Thanks,

Scott

This should scroll to the top of your modal. You can put it right after your load in the click listener to get it to scroll.

$(".postmodal-container").scrollTop(0)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM