【问题标题】:Wordpress - Scroll to top after post load with AjaxWordpress - 使用 Ajax 加载后滚动到顶部
【发布时间】:2014-05-08 10:33:17
【问题描述】:

我在 Wordpress 中创建了一个作品集,其中的帖子直接在同一页面上打开。一直很困难,但我设法 - following these steps - 让一切正常......或几乎。

我现在想要确保当用户点击一个元素时,页面滚动到顶部以查看产品详细信息。我尝试了各种方法都没有成功:(

这是网站:http://www.grafichepioppi.it/category/portfolio/

这是我的代码:

$(document).ready(function(){

$.ajaxSetup({
    cache:true, 
    async: true, 
    complete:function(){
        $('body,html').animate({scrollTop: 0}, 800);
   }});

$("a.link-portfolio").click(function(){

    var post_url = $(this).attr("href");
    var post_id = $(this).attr("rel");

    $("#portfolio-featured").html("<div class='loading-ajax'></div>").fadeIn(500);


     $("#portfolio-featured").load(post_url, function() {

    $('.portfolio-featured').show( 4000 );  
});

window.location.hash = post_id;

return false;
    });
});

关于如何做到这一点的任何想法?

【问题讨论】:

  • 嗯...然后将$('body,html').animate({scrollTop: 0}, 800);$.ajaxSetup({...})移动到$("a.link-portfolio").click(..)
  • 我试过了,还是不行。 Chrome的控制台没有错误,我不知道错误在哪里

标签: jquery ajax wordpress scroll


【解决方案1】:

这有帮助吗?

     $("#portfolio-featured").load(post_url, function() {
       $('.portfolio-featured').show( 4000 );  
       $("html, body").animate({  
           scrollTop: $(this).offset().top - 300 }, 400); //to top
     });

【讨论】:

    猜你喜欢
    • 2012-04-04
    • 1970-01-01
    • 1970-01-01
    • 2017-07-05
    • 2016-07-04
    • 1970-01-01
    • 2015-03-19
    • 2016-08-26
    • 1970-01-01
    相关资源
    最近更新 更多