作者:chen-yu2502881617 | 来源:互联网 | 2023-09-10 16:22
Isthereaway,usingJquerytogrowandthenshrinkanimage(withanimationsoitlookssmooth)on
Is there a way, using Jquery to grow and then shrink an image (with animation so it looks smooth) on hovering without affecting the layout too much (I'm assuming the padding would have to shrink and then grow as well).
有没有办法,使用Jquery增长然后缩小图像(动画使其看起来很光滑)悬停而不会过多地影响布局(我假设填充必须缩小然后再增长)。
With a bit of messing around, I finally came up with the solution, thanks to everyone who helped out.
随着一些麻烦,我终于想出了解决方案,感谢所有帮助过的人。
7 个解决方案
You could wrap the image in a div (or whatever html element you think is appropriate, li etc) with it's overflow set to hidden. Then use jQuery .animate to grow that div, in whatever way you like.
您可以将图像包装在div中(或者您认为合适的任何html元素,li等),并将其溢出设置为隐藏。然后使用jQuery .animate以你喜欢的方式增长div。
So for example the html could be
所以例如html可能是
Then your css would look like
然后你的CSS会是这样的
.grower {width:250px;height:250px;overflow:hidden;position:relative;}
So your image is essentially cropped by the div, which you can then grow on any event to reveal the full size of the image using jQuery
因此,您的图像基本上被div裁剪,然后您可以在任何事件上增长,以使用jQuery显示图像的完整大小
$('.grower').mouseover(function(){
//moving the div left a bit is completely optional
//but should have the effect of growing the image from the middle.
$(this).stop().animate({"width": "300px","left":"-25px"}, 200,'easeInQuint');
}).mouseout(function(){
$(this).stop().animate({"width": "250px","left":"0px"}, 200,'easeInQuint');
});;
NB: You may want to add in additional css into your js, like an increased z-index to your div so that it can grow over the layout etc
注意:您可能希望在js中添加额外的css,比如增加了对div的z-index,以便它可以在布局上增长等
-- JS
$( ".container" ).toggle({ effect: "scale", persent: 80 });
--More info
http://api.jqueryui.com/scale-effect/
- 更多信息http://api.jqueryui.com/scale-effect/