として整理された画像ギャラリーを取得しました<ul>
。すべての画像は<li>
要素内にあり、それらの画像の 1 つにマウスを移動すると、ユーザーに視覚的なフィードバックを提供するために拡大する必要があります。animate() を使用して画像のサイズを変更すると、サイズ変更された画像がより多くのスペースを使用するため、他の画像が横に押し出されます。
したがって、画像要素のクローンを作成し、元の画像の上に浮かせてから、アニメーションを呼び出しました。これには、複製された画像がポップアップするとすぐに onMouseOut() が呼び出されるという問題が伴います。そのため、ネストされた hover() 関数が必要であり、これが複雑になった場所です。
2 つのエラーが発生しましたが、その原因がわかりません。最初のものは、 animate() が複製された画像を元の右の境界線を超えて拡大させないことです.2つ目は、マウスをギャラリー上ですばやく移動すると、奇妙な拡大/縮小動作が発生することです.
html:
<ul id="gallery1" class="gallery_container">
<li class="frame">
<a href=""><img src="pic1.jpg" class="picture" /></a></li><li class="frame">
<a href=""><img src="pic2.jpg" class="picture" /></a></li><li class="frame">
<a href=""><img src="pic3.jpg" class="picture" /></a></li>
</ul>
CSS:
.picture
{
height: 200px;
border: 0px;
margin: 0px;
padding: 0px;
}
.frame
{
display: inline-block;
position: relative;
margin: 0px;
margin-right:8px;
padding: 0px;
}
.frame a
{
padding: 0px;
margin: 0px;
}
.gallery_container
{
height: 200px;
width: 150%;
position: relative;
top: 4px;
padding: 0px;
margin: 0px;
}
そして最後に、私にそれらの頭痛の種を与えているコード:
$(document).ready(function()
{
var zooming = false;
var zoom = 4;
var speed_zoom = 100;
$('.gallery_container li a').hover(function(element)
{
// disable zooming to prevent unwanted behavior
if(zooming) return;
zooming = true;
$(this).after( $(this).clone(false) );
$(this).next().attr('id', 'focus_frame');
},
function(element) // when the new element pops up, onmouseout is triggered, since the focus_frame is in front of the image
{
$(this).next().hover(function(element)
{
// we need to re-position the element in the dom-tree, since it needs to grow out of a container with overflow: hidden
$('#focus_frame img').animate({'left' : zoom * -1, 'top' : zoom * -1, 'height' : 200+(zoom*2), 'width' : $('#focus_frame img').outerWidth() + (zoom*2)}, speed_zoom);
},
function(element)
{
$(this).remove();
zooming = false;
});
});
});