0
我有以下代碼,它將wordpress帖子加載到工作得很好的模式中。唯一的問題是,當其中一個導航鏈接被點擊時,它會加載下一個帖子而不滾動到頂部。單擊導航後滾動模式到頂部
有沒有什麼辦法可以讓模態滾動到頂部時,其中一個導航鏈接被點擊?
(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);
感謝,
斯科特
感謝,它的工作原理,但有沒有辦法我可以做到這一點,直到模態有新的內容,才能達到頂端?因爲目前它進入頂端,然後模態更新與新帖子看起來很奇怪 –
它確定我用$(「.postmodal」).empty(); –