Jquery Wordpress-使用Ajax加载后滚动到顶部
我在Wordpress中创建了一个公文包,其中的帖子直接在同一页面上打开。这很困难,但我设法--使一切顺利。。。或者差不多 我现在想要的是确保,当用户单击某个元素时,页面滚动到顶部以查看产品详细信息。我尝试了各种方法,但都没有成功:( 这是网站: 这是我的代码:Jquery Wordpress-使用Ajax加载后滚动到顶部,jquery,ajax,wordpress,scroll,Jquery,Ajax,Wordpress,Scroll,我在Wordpress中创建了一个公文包,其中的帖子直接在同一页面上打开。这很困难,但我设法--使一切顺利。。。或者差不多 我现在想要的是确保,当用户单击某个元素时,页面滚动到顶部以查看产品详细信息。我尝试了各种方法,但都没有成功:( 这是网站: 这是我的代码: $(document).ready(function(){ $.ajaxSetup({ cache:true, async: true, complete:function(){ $('bo
$(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;
});
});
$(文档).ready(函数(){
$.ajaxSetup({
是的,
async:true,
完成:函数(){
$('body,html').animate({scrollTop:0},800);
}});
$(“a.link-portfolio”)。单击(函数(){
var post_url=$(this.attr(“href”);
var post_id=$(this.attr(“rel”);
$(“#公文包特色”).html(“”).fadeIn(500);
$(“#公文包特色”).load(发布url,函数(){
$('portfolio featured').show(4000);
});
window.location.hash=post_id;
返回false;
});
});
有什么办法吗?这有帮助吗
$("#portfolio-featured").load(post_url, function() {
$('.portfolio-featured').show( 4000 );
$("html, body").animate({
scrollTop: $(this).offset().top - 300 }, 400); //to top
});
嗯…然后将
$('body,html').animate({scrollTop:0},800);
从$.ajaxSetup({…})
移动到$('a.link-portfolio')。单击(…)
我试过了,但不起作用。Chrome的控制台没有错误,我不知道错误在哪里