淡入淡出图像位置
我有一个这样的列表:
<ul>
<li><a href="#"><img src="/userfiles/test.png" alt="" /></a></li>
<li><a href="#"><img src="/userfiles/test2.png" alt="" /></a></li>
</ul>
每个图像的宽度为 950 像素,高度为 600 像素。
高度的前 300 像素是鼠标移出图像,最后 300 像素是我想要淡入淡出的鼠标悬停图像。这可能吗?
我有这个 CSS 来控制要显示的图像:
ul { list-style: none; padding: 0; margin: 0; }
ul li { width: 950px; height: 300px; overflow: hidden; position: relative; }
ul li img {
display: block;
position: absolute;
top: 0;
left: 0;
}
此代码只是将图像的最后 300 个像素向上移动,但我不想移动它,而是想让图像在“其他”上淡出不透明度:.
<script type="text/javascript">
$(document).ready(function () {
$("ul li img").mouseover(function () {
$(this).stop().animate(
{ top: "-300px" },
{ duration: 300 })
})
.mouseout(function () {
$(this).stop().animate(
{ top: "0" },
{ duration: 300 })
})
});
</script>
I have a list like this:
<ul>
<li><a href="#"><img src="/userfiles/test.png" alt="" /></a></li>
<li><a href="#"><img src="/userfiles/test2.png" alt="" /></a></li>
</ul>
Each of these image is 950 pixels wide and 600 pixels in height.
The first 300 pixel in height is the mouse-out image and the last 300 pixel is the mouse-over image I want to fade over. Is this possible?
I have this CSS to control what image to show:
ul { list-style: none; padding: 0; margin: 0; }
ul li { width: 950px; height: 300px; overflow: hidden; position: relative; }
ul li img {
display: block;
position: absolute;
top: 0;
left: 0;
}
This code just moves the last 300 pixels of the image up, but instead of moving it I want to opacity fade the image over the "other":.
<script type="text/javascript">
$(document).ready(function () {
$("ul li img").mouseover(function () {
$(this).stop().animate(
{ top: "-300px" },
{ duration: 300 })
})
.mouseout(function () {
$(this).stop().animate(
{ top: "0" },
{ duration: 300 })
})
});
</script>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
刚刚完成这个实施,感谢您提供了一个很好且相当简短的练习。
首先,请在此处查看最终结果。
实施说明:
background-image
而不是独立的img
元素,那么这会容易得多(我什至可以说微不足道),并且它的性能也会更高。img
元素添加一个“姐妹”div
并对其进行适当的样式设置。最重要的是设置其background-image
属性,它允许我们只显示图片所需的一半。Just finished implementing this, thanks for presenting a nice and reasonably short excercise.
First off, see the end result here.
Implementation notes:
background-image
rather than a standaloneimg
element, and it would also be more performant.div
for eachimg
element and styling it appropriately. The most important is setting itsbackground-image
property, which allows us to show only the desired half of the picture.我想我已经有了主意。工作示例:
http://jsfiddle.net/avall/RMWt8/1/
解决方案使用
overflow
风格并使用图层(z-index
)。当你用鼠标从下到上移动时,由于中心线错误,它应该稍微升级,但你应该明白这个想法。
I think I've got the idea. The working example:
http://jsfiddle.net/avall/RMWt8/1/
The solution uses
overflow
style and play with layers (z-index
).It should be slightly upgraded because of center line bug when you go with your mouse from bottom to top but you should get the idea.