javascript - 图像在悬停时跳起来

标签 javascript jquery html css

如果你看一下the fiddle你会知道我在说什么。我正在尝试创建这样一种效果,即当用户将鼠标悬停在其中一张图像上时,他会从图像上滑下删除栏。
问题是,当我将鼠标悬停在一张图片上时,其他图片由于某种奇怪的原因会跳下来。
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”时,您无法点击,因为它很快就会消失。 非常感谢!

最佳答案

您有.showdisplay:inline-block;。默认情况下,它们的 vertical-align 最初设置为 baseline。 <强> See MDN Reference

如果您将 .show 的样式设置为包含 vertical-align:top;,这将缓解此问题。

Fixed Demo

关于javascript - 图像在悬停时跳起来,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24484891/

相关文章:

javascript - Ag-Grid 启用单个 rowNode 的复选框选择

javascript - 滚动顶部在 angular2 中无法正常工作

javascript - 使用缩略图库切换多个图像

javascript - 使用 jquery 添加元素后隐藏搜索栏

jquery - GET Ajax 在响应中返回 html 代码而不是 json 对象

javascript - 想要在将元素添加到列表时平滑地增加容器 div 的高度

javascript - 如何只按 1 个按钮使图像改变 3 次?

javascript - 通过 json 以 10ms 的间隔检查/显示变量值

javascript - FabricJS - 为什么形状内的旋转对象不垂直居中?

javascript - 如果我从选择中更改,则从数据列表中过滤选项值