2013-01-12 49 views
1

我目前正在圖像庫中工作。除了在谷歌瀏覽器中,當您將鼠標懸停在頂部行上時,它會正常工作,下面的行將開始震動並移動。你可以找到一個工作示例here圖片在使用jquery進行放大時懸停在Google chrome上的圖像

的HTML:

 <div id="gallery"> 
      <a href="<?php echo'?img=$imgname';?>" > 
          <span c 

lass="title"><?php echo'$imgtitle';?></span> 
          <img src="http://ivojonkers.com/fotorichard/images_slider/1.jpg" /> 
         </a> 

         <a href="<?php echo'?img=$imgname';?>" > 
         <span class="title"><?php echo'$imgtitle';?></span> 
          <img src="http://ivojonkers.com/fotorichard/images_slider/1.jpg" /> 
         </a> 
         <a href="<?php echo'?img=$imgname';?>" > 
         <span class="title"><?php echo'$imgtitle';?></span> 
          <img src="http://ivojonkers.com/fotorichard/images_slider/1.jpg" /> 
         </a> 

         <a href="<?php echo'?img=$imgname';?>" > 
         <span class="title"><?php echo'$imgtitle';?></span> 
          <img src="http://ivojonkers.com/fotorichard/images_slider/1.jpg" /> 
         </a> 

         <a href="<?php echo'?img=$imgname';?>" > 
         <span class="title"><?php echo'$imgtitle';?></span> 
          <img src="http://ivojonkers.com/fotorichard/images_slider/1.jpg" /> 
         </a> 
         <a href="<?php echo'?img=$imgname';?>" > 
         <span class="title"><?php echo'$imgtitle';?></span> 
          <img src="http://ivojonkers.com/fotorichard/images_slider/1.jpg" /> 
         </a> 

         <a href="<?php echo'?img=$imgname';?>" > 
         <span class="title"><?php echo'$imgtitle';?></span> 
          <img src="http://ivojonkers.com/fotorichard/images_slider/1.jpg" /> 
         </a> 
         <a href="<?php echo'?img=$imgname';?>" > 
          <span class="title"><?php echo'$imgtitle';?></span> 
          <img src="http://ivojonkers.com/fotorichard/images_slider/1.jpg" /> 
         </a> 

         <a href="<?php echo'?img=$imgname';?>" > 
          <span class="title"><?php echo'$imgtitle';?></span> 
          <img src="http://ivojonkers.com/fotorichard/images_slider/1.jpg" /> 
         </a> 
         <a href="<?php echo'?img=$imgname';?>" > 
         <span class="title"><?php echo'$imgtitle';?></span> 
          <img src="http://ivojonkers.com/fotorichard/images_slider/1.jpg" /> 
         </a> 
         <a href="<?php echo'?img=$imgname';?>" > 
         <span class="title"><?php echo'$imgtitle';?></span> 
          <img src="http://ivojonkers.com/fotorichard/images_slider/1.jpg" /> 
         </a> 
    </div> 

的CSS

#gallery { 
    width: 100%; 
    margin-top: 100px; 
    padding-bottom: 100px; 
    display:block; 
    text-align:center; 
} 

#gallery a { 
    display: inline-block; 
    margin: 0 12.5px 25px 12.5px; 
    position: relative; 
    height:150px; 
    width:225px; 
} 

#gallery a img { 
    height:150px; 
    width:225px; 
    position:relative; 
} 

jQuery的

$(document).ready(function() { 
    $("#gallery a img").hover(function(){ 
      $(this).css({"z-index":"99"}); 
      $(this).stop(true, false).animate({ "margin-left":"-112.5px", 
        "margin-top":"-150px", 
        "bottom":"-75px", 
        "height":"300px", 
        "width":"450px" 
        }); 
     }, function() { 
     $(this).css({"z-index":"0"}); 
      $(this).stop(true, false).animate({"height":"150px", 
        "width":"225px", 
        "margin-left":"0px", 
        "margin-top":"0px", 
        "bottom":"0px" 
       }); 
     }); 
}); 

附:如果你縮小更多,它更引人注目。

在此先感謝您的幫助。

+1

工作正常,我在Chrome中,win8的 – aurbano

+0

我目前對鉻的Win7上的最新版本,當你將鼠標懸停img的第一行,你可以看到底部行開始振動 – Ivo

+0

Windows 7,最新版本的chrome,它對我很好。 –

回答

0

我固定的問題與你的球員的幫助。我所要做的就是改變這種:

// ... 
$(this).stop(true, false).animate({"height":"150px", 
    "width":"225px", 
    "margin-left":"0px", 
    "margin-top":"0px", 
    "bottom":"0px" 
}, function(){ 
    // Do this last 
    $(this).css({"z-index":"0"}); 
}); 
// ... 

這樣:

#gallery a img { 
height:150px; 
width:225px; 
position:absolute; 
left:0px; 
} 
+1

您接受的正確答案不使用這種方法,您爲什麼接受答案是正確的? – Madbreaks

+1

這一個也工作:) – Ivo

1

嘗試將z-index的恢復(回零)到動畫的回調:

// ... 
$(this).stop(true, false).animate({"height":"150px", 
    "width":"225px", 
    "margin-left":"0px", 
    "margin-top":"0px", 
    "bottom":"0px" 
}, function(){ 
    // Do this last 
    $(this).css({"z-index":"0"}); 
}); 
// ... 

的jsfiddle沒有工作對我來說今天由於某種原因,或者我把一個在一起。

+0

同樣的問題jsfiddle不適合我 – Ivo

+0

如果您覺得我回答了您的問題,請點擊相應的複選框投票櫃檯。謝謝 – Madbreaks

2

我認爲最好的選擇是複製你的基礎圖像並放大它。

$(function() { 
     $("#gallery a img").mouseenter(function(){ 
      var d = $(this).clone().addClass('preview') 
      .css({position:'absolute',top:$(this).position().top, left:$(this).position().left,zIndex:99}) 
      .insertAfter($(this)).animate({ "margin-left":"-112.5px", 
         "margin-top":"-150px", 
         "bottom":"-75px", 
         "height":"300px", 
         "width":"450px" 
}).mouseleave(function(){ 
      $(this).animate({"height":"150px", 
         "width":"225px", 
         "margin-left":"0px", 
         "margin-top":"0px", 
         "bottom":"0px" 
              }, 
         function(){$(this).remove()}); 
      }) 
      }); 
    }); 

試試jsfiddle

+1

在Chrome的負底部由於某種原因不起作用,使用頂部,而不是http://jsfiddle.net/hbNvu/3/ – antejan

+0

現在問題是這個劇本它總是完成動畫在我的腳本它停止動畫,當你離開 – Ivo

+1

只需將停止(true,false)添加到mouseleave處理程序:http://jsfiddle.net/hbNvu/13/ – kreig

1

這會將所有圖像向右移動一點(所以只需稍加額外的工作),但將圖像設置爲絕對可以擺脫對我的振動。

#gallery a img { 
height:150px; 
width:225px; 
position:absolute; 
} 
+0

這是更好的解決方案恕我直言 - 用Web Inspector做了一個快速測試,並像魅力一樣工作。它很簡潔。 – user916011

1

取代:

#gallery a { 
display:inline-block; 
/* ... */ 
} 

#gallery a { 
display:block; 
float:left; 
/* ... */ 
}