jQuery FadeOut div 有效 - .load 然后 .fadeIn div 无效

发布于 2024-09-14 06:58:54 字数 938 浏览 6 评论 0原文

我正在开发一个 WordPress 3.0 主题,这是我的第一个带有一些 jQuery 增强功能的主题。我正在尝试淡出和淡入每个帖子区域的分页。这个想法是,当用户单击“上一页”或“下一页”箭头时,列出的帖子将淡出,下一页帖子将加载然后淡入。

淡出效果很好,但新内容不会淡出进去后,它会突然弹出,不会褪色。它看起来不错,但它没有做我想做的事,我无法弄清楚为什么。

这是它现在在开发环境中工作的两个地方(我还没有在 FF 3.5、FF 3.6 和 Chrome 之外进行真正的跨浏览器测试,所以如果您使用 IE,它可能无法按预期工作):

http://kendraschaefer.com/mandapop/gallery/ http://kendraschaefer.com/mandapop/blog/

这是相应的 jQuery:

$(document).ready(function(){
    $('#postPagination a').live('click', function(e){
        $('#blogListColWrapper, #galleryListColWrapper').fadeOut(200).load(link + ' #blogListCol', function(){ 
        $('#blogListColWrapper, #galleryListColWrapper').fadeIn(300); 
        Cufon.refresh(); });
    });

});

我已经尝试了我能想到的一切。任何想法将不胜感激。

I'm developing a WordPress 3.0 theme, my first theme with a bit of jQuery enhancement. I'm trying to fade out and fade in the pagination on each posts area. The idea is that when a user click the "prev" or "next" arrows, the listed posts will fade out, the next page of posts will load and then fade in.

The fadeouts work fine, but the new content doesn't fade in, it just pops in with no fade. It looks OK, but it's not doing what I want and I can't sort out why.

Here are the two places it's working now on the dev environment (I haven't really cross browser tested yet outside of FF 3.5, FF 3.6 and Chrome, so if you're on IE it may not work as expected):

http://kendraschaefer.com/mandapop/gallery/
http://kendraschaefer.com/mandapop/blog/

And here's the corresponding jQuery:

$(document).ready(function(){
    $('#postPagination a').live('click', function(e){
        $('#blogListColWrapper, #galleryListColWrapper').fadeOut(200).load(link + ' #blogListCol', function(){ 
        $('#blogListColWrapper, #galleryListColWrapper').fadeIn(300); 
        Cufon.refresh(); });
    });

});

I've tried everything I can think of. Any ideas would be much appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

伴我心暖 2024-09-21 06:58:54

即时淡入是因为链接正在执行它的默认行为...加载新页面,观察您的 URL 以查看它的变化:)

我认为总的来说您正在寻找的是这样的:

$('#postPagination a').live('click', function(e){
  var link = this.href;
  $('#blogListColWrapper, #galleryListColWrapper').fadeOut(200).each(function() {
    $(this).load(link + ' #' + this.id, function(){ 
      $(this).fadeIn(300); 
      Cufon.refresh(); 
    });
  });
  e.preventDefault();
});

这有一些变化,首先使用 e.preventDefault() 来阻止链接从实际进入页面开始。在 link 未定义后,您需要从您单击的链接中提取 href 属性。有几种方法可以处理 #id 部分.load() 你正在做的事情,我只是做了一个简单的 .each() 此处,其中 this 指的是实际加载的 div,因此您可以获取 id 属性。


这是一种没有each的替代方法,但如果两者#blogLostColWrapper#galleryListColWrapper都在页面中,它会更容易崩溃......希望情况并非如此:

$('#postPagination a').die().live('click', function(e) {
  $('#blogListColWrapper,#galleryListColWrapper').fadeOut(200)
    .load(this.href + ' #blogListColWrapper,#galleryListColWrapper', function() {
      $(this).fadeIn(300); 
      Cufon.refresh(); 
    });
  e.preventDefault();
});

The instant fade-in is because the link is doing it's default behavior...loading a new page, watch your URL to see it change :)

I think overall what you're looking for is something like this:

$('#postPagination a').live('click', function(e){
  var link = this.href;
  $('#blogListColWrapper, #galleryListColWrapper').fadeOut(200).each(function() {
    $(this).load(link + ' #' + this.id, function(){ 
      $(this).fadeIn(300); 
      Cufon.refresh(); 
    });
  });
  e.preventDefault();
});

This has a few changes, first the e.preventDefault() to prevent the link from actually going to the page. After that link was undefined, you need to pull the href attribute from the link you're clicking. There are a couple of ways to go about the #id part of the .load() you're doing, I just did a simple .each() here, where this refers to the div that's actually loading so you can grab the id property.


Here's an alternative way without the each, but it'll break more easily if both #blogLostColWrapper and #galleryListColWrapper are in the page...hopefully that's not the case:

$('#postPagination a').die().live('click', function(e) {
  $('#blogListColWrapper,#galleryListColWrapper').fadeOut(200)
    .load(this.href + ' #blogListColWrapper,#galleryListColWrapper', function() {
      $(this).fadeIn(300); 
      Cufon.refresh(); 
    });
  e.preventDefault();
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文