动态加载内容的动画效果 - jQuery

时间:2011-08-02 19:25:13

标签: jquery html load fade

$(function() {
 $("a").hover(
  function() {
   $(this).animate({color: "blue"}, 400);
  }, function() {
   $(this).animate({color: "white"}, 400);
 })
 $(".left").fadeOut("slow").load("created.php").fadeIn("slow");
})

我希望created.php页面中的链接(a)具有悬停效果。我该怎么办?

2 个答案:

答案 0 :(得分:3)

使用live绑定处理程序。这样,页面中加载的任何新“a”也将获得悬停效果。

$(function() {
     $("a").live(
     { mouseenter: function() {
             $(this).animate({color: "blue"}, 400);
          }, 
       mouseleave: function() {
            $(this).animate({color: "white"}, 400);
          }
     })
     $(".left").fadeOut("slow").load("created.php").fadeIn("slow");
});

注意:使用livehover只需要一个处理程序。另一种方法是指定mouseentermouseleave处理程序。

答案 1 :(得分:1)

您想使用jquery live方法。

 $("a").live( {mouseover: function() {
    // do something on mouseover
  },
mouseout: function() {
    // do something on mouseout
  }
});