图像在悬停时跳起来
Images jump up on hover
如果你看看小提琴你就知道我在说什么了。我试图创造这样一种效果,当用户将鼠标悬停在其中一张图像上时,他会从图像上滑下移除条。
问题是,当我把鼠标悬停在一个图像上时,其他图像会因为一些奇怪的原因跳下来。
HTML:
<div class="show">
<a href="#">
<img alt="Pic1" class="thumbnail" />
</a>
<div class="remove-bar">
<a href="#">r </a>
</div>
</div>
<div class="show">
<a href="#">
<img alt="Pic2" class="thumbnail" />
</a>
<div class="remove-bar">
<a href="#"> r</a>
</div>
</div>
<div class="show">
<a href="#">
<img alt="Pic3" class="thumbnail" />
</a>
<div class="remove-bar">
<a href="#">r</a>
</div>
</div>
CSS: .show {
display: inline-block;
}
.thumbnail {
width: 12.5em;
height: 18.750em;
margin: 1em;
margin-bottom: 0;
cursor: pointer;
box-shadow: 0 1px 2px lighten(#333, 30%);
}
.remove-bar {
text-align: right;
width: 11.9em ;
margin-top: 0;
margin-left: 1em;
background-color: blue;
padding: 5px;
} .remove-bar a {
color: white;
}
JS:
$('.remove-bar').hide();
$('.show a').hover(function() {
$(this).next('div.remove-bar').slideDown(100);
}, function() {
$(this).next('div.remove-bar').slideUp(100);
});
另外,请注意,当您将鼠标悬停在图像上并尝试单击"r"时,您不能,因为它会很快消失。谢谢!
您有您的.show
项display:inline-block;
。默认情况下,vertical-align
初始设置为baseline
。参见MDN参考
如果你将.show
的样式设置为包含vertical-align:top;
,这将缓解这个问题。
将position: absolute
添加到remove-bar
类
.remove-bar {
text-align: right;
width: 11.9em ;
margin-top: 0;
margin-left: 1em;
background-color: blue;
padding: 5px;
position: absolute;
}
和position: relative
在父div类
.show {
display: inline-block;
position: relative;
}
你可以用CSS3代替JavaScript!此外,您应该使用vertical-align:top;
作为顶级元素。
.show {
display: inline-block;
vertical-align: top;
}
.show a + div {
height: 0px;
padding: 0px 5px;
transition: all 0.1s linear;
}
.show a:hover + div {
height: auto;
padding: 5px;
}
没有JS !http://jsfiddle.net/samliew/Smwd6/
我来晚了一点,但是这里有一个可以解决您的jQuery问题的Fiddle。玩设置,以获得恰到好处。
http://jsfiddle.net/dRyGL/25/$('.remove-bar').hide();
var bar = null;
$('.show a').hover(function() {
bar = $(this).next('div');
bar.slideDown(100);
}, function() {
setTimeout( function(){
if(bar.is(":hover")){
}else{
bar.slideUp(100);
}
},400);//give slow folks 200ms to get to the bar element
});
$('.remove-bar').hover(function(){
}, function(){
$(this).slideUp(100);
}
);
$(document).mousemove(function() {
setTimeout( function() {
$('.remove-bar').each(function() {
var parent = $(this).parent();
if($(this).is(':hover')) {
}else{
if(parent.is(':hover') === false)
{
$(this).slideUp(100);
}
}
});
},400);
});
我试图涵盖所有可能导致remove-bar
div错误打开的边缘情况。
如果您将float:left
添加到.show
类中,则可以纠正此问题。
相关文章:
- AngularJS:我可以跳过函数参数回调吗
- 当鼠标悬停在文本中的单词上时显示警报
- node.js:setInterval()正在跳过调用
- 每当您在选择器内移动鼠标时,悬停功能就会重复
- 手风琴可点击并悬停
- 悬停功能触发器
- 如何在鼠标悬停时在另一个图像上滑动图像.
- 鼠标悬停事件影响列表中所有行中的按钮,而不仅仅是特定按钮
- Bootstrap粘贴Nav使下面的Div跳起来
- 点击'''元素,触发它的悬停处理程序,而不是跳转到链接
- 为什么jQuery修改的文本在Safari中悬停时看起来更轻?
- 这可能吗?当鼠标悬停在你管视频然后播放视频,当鼠标悬停然后停止视频.它看起来像facebook
- 图像在悬停时跳起来
- 为什么我的菜单在第二次拖动到新项目时跳起来了?
- 当上面的元素淡入时,页面会跳起来
- 鼠标悬停跳过一些元素,当我'
- 当表格在IE中获得焦点时,表格滚动条会跳起来
- 设置宽度动画会导致内部元素从未知高度跳起来
- 当用户的光标悬停在图像上时,如何使其跳转到页面上的特定坐标
- 我如何样式高图选择看起来像悬停