0

我试图让圈子对我的 jquery .hover 做出反应。这是我的js:

jQuery.fn.center = function () {
this.css("position","absolute");
this.css("top", Math.max(0, (($(window).height() - this.outerHeight()) / 2) + 
                                            $(window).scrollTop()) + "px");
this.css("left", Math.max(0, (($(window).width() - this.outerWidth()) / 2) + 
                                            $(window).scrollLeft()) + "px");
return this;
};


$(document).ready(function()
{
    $('#logo').center();
    j=8;
    size=200;
    $.each($(".circle"), function() {
        $(this).css('z-index', j);
        $(this).css({
            height: size+"px",
            width: size+"px",
            borderRadius: size+"px",
            });
        size = size+50;
        $(this).center();
        j--;
    });

});

  $(".circle").hover(
    function() {
      $(this).animate({
        height: '+=25px',
        width: '+=25px',
        top: '-=12.5px',
        left: '-=12.5px'
        }, 'fast'
      );
    },
    function() {
      $(this).animate({
        height: '-=25px',
        width: '-=25px',
        top: '+=12.5px',
        left: '+=12.5px'
        }, 'fast'
      );
    }
  );

这是我的正文 HTML:

    <div id='logo'><img src='_Source/Logo.png' alt='RB'/></div>
<div id='a1' class='circle'></div><div id='g1' class='circle'></div>
<div id='a2' class='circle'></div><div id='g2' class='circle'></div>
<div id='a3' class='circle'></div><div id='g3' class='circle'></div>
<div id='a4' class='circle'></div><div id='g4' class='circle'></div>

这适用于jsfiddle,here

但是,在我的网站上它不起作用,在这里

如果我不是已经秃顶,我会扯掉我的头发。

谢谢。

4

1 回答 1

1

.hover()绑定调用位于绑定范围之外,.ready()位于<head>. 最终效果是您试图.hover在加载 DOM 之前绑定回调。解决此问题的最简单方法是将其移至 .ready() 绑定函数的范围内。

于 2012-06-24T23:39:57.467 回答