我正在尝试使用jQuery创建一个幻灯片输出div。当图片悬停在上面时,一个div应该会滑出,部分覆盖照片(其中包含信息)。
我已经把Javascript组装好了,但是我似乎不能让它工作。
信息是display:none的,但当图像悬停在上方时应显示(应从右侧滑出)
发布于 2012-10-16 06:33:26
这里有一种方法:
$("#snoodLink").hover(
function() {
$('#snoodInfo').animate({
left: 0,
right: 0
}, 500);
}, function() {
$('#snoodInfo').animate({
left: '-100%',
right: '100%'
}, 500);
});它使用以下CSS:
.product {
/* ensures the positioned text element isn't
visible before sliding in/after sliding out */
overflow: hidden;
}
#snoodInfo {
position: absolute;
top: 0;
left: -100%;
right: 100%;
width: 100%;
background-color: rgba(255,255,255, 0.5);
}顺便说一句,这可以用CSS来完成(对于旧的IE来说,这是一种优雅的降级):
.product {
position: relative;
overflow: hidden;
/* following just center the image/element
absolutely not necessary */
width: 50%;
margin: 1em auto;
}
.product img {
width: 100%;
}
/* this is the #snoodInfo element, given a class
insead of id, to make it more generic */
.info {
position: absolute;
top: 0;
left: -100%;
right: 100%;
width: 100%;
/* to enforce the fade-in/fade-out */
color: transparent;
background-color: transparent;
/* trying to cover as many browsers
as possible, omitting early/old IE
but filters could (probably) be used */
-webkit-transition: all 1.5s linear;
-moz-transition: all 1.5s linear;
-ms-transition: all 1.5s linear;
-o-transition: all 1.5s linear;
transition: all 1.5s linear;
}
.product:hover .info {
left: 0%;
right: 0%;
color: #000;
background-color: #fff;
background-color: rgba(215,50,50,0.8);
-webkit-transition: all 1.5s linear;
-moz-transition: all 1.5s linear;
-ms-transition: all 1.5s linear;
-o-transition: all 1.5s linear;
transition: all 1.5s linear;
}https://stackoverflow.com/questions/12904590
复制相似问题