簡體   English   中英

為什么.hover函數不起作用?如何讓.hover函數忽略拐角半徑之外的區域?

[英]Why isn't .hover function working and how can I get the .hover function to ignore the the area outside of the corner radius?

我正在嘗試讓圈子對我的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, 在這里

但是,在我的網站上, 功能不起作用

如果我還沒禿頭,那我就要把頭發扯掉了。

謝謝。

.hover()綁定調用位於.ready()綁定范圍之外,並且位於<head> 最終結果是您試圖在加載DOM之前綁定.hover回調。 解決此問題的最簡單方法是將其移入.ready()綁定函數的范圍。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM