【发布时间】:2014-09-08 22:44:13
【问题描述】:
我有一页全是缩略图。将鼠标悬停在一张上时,我想放大它,而不会影响其余图片的布局。
每张图片都在一个包装 div 中,当图片放大时保持静止
我可以用 CSS 做到这一点:
- 将 z-index 从 0 更改为 1
- 将显示属性更改为“绝对”
- 设置 left:0 和 top:0(以防万一)
-
然后设置 width:340px 和 height:auto (我认为 ie8 需要)。 CSS
.wrapper:hover > .Img { 宽度:300px;位置:绝对;z-index:1;左:0;顶部:0; }
但我想为尺寸的增加制作动画。我开始使用: $('.wrapper').hover(function() {... 但后来读到悬停只能有一个功能。
所以我尝试了 mouseenter 和 mouseleave 都没有成功。
我尝试的是:
$('.Wrapper.).mouseenter(function() {
$('.Img').animate({ zIndex:1 },1,"swing" ); /* this line works */
document.getElementsByClassName('.Img').style.zIndex="1"; /* this doesnt */
document.getElementsByClassName('Img').style.position="absolute"/* this doesnt */
$('.Img').animate({ position:"absolute" },1,"swing"); /* this doesnt */
$('.Img').animate({width: '300px', height: '240px'},5000,"swing");
});
$("#testXX").mouseleave(function() {
/* with the reverse of above */
});
请有人指出我正确的方向。
--- 已编辑?稍后添加:--- 谢谢你的想法。我做了更多的研究,问题似乎是:
使用 javascript,我不知道如何将位置更改为“绝对”, 但我现在可以更改其他属性。
document.getElementById(this).position='absolute'; doesnt work
document.getElementsByClassName('.Img').style.position="absolute"; doesnt work
$('.Img').animate({ position:'absolute' },001,'swing'); doesnt work!
我想我可以混合使用 CSS(将更改为绝对值)和 Javascript(进行其他动画),但我担心会导致页面其余部分的显示效果的顺序/时间。
fyi:CSS 版本在这里: http://www.frog-records.co.uk/.... 或者(如果您在阅读本文时解决了)动画版本将在那里;-)
【问题讨论】:
-
我相信这是一个错字?
$('.Wrapper.)
标签: javascript jquery jquery-animate