【发布时间】:2017-10-10 15:43:45
【问题描述】:
您好,我很想知道在悬停时滚动到图像底部的最佳方法。该图像位于一个包装器中,溢出隐藏应用到它很长。理想情况下,平滑滚动到底部是我要查看隐藏图像的其余部分的内容。
我一直在玩 jquery 试图让它工作,但我陷入了混乱。不确定我的代码是否在正确的轨道上。
感谢任何帮助
$('#image-wrap img').on('hover', function() {
var target = $(this),
height = target.height(),
scrollHeight = target.prop('scrollHeight');
target.animate({
scrollTop: scrollHeight - height
}, 2000);
});
#main-wrapper {
width: 600px;
margin: 0 auto;
}
#box-wrapper {
position: relative;
}
#box {
width: 100%;
height: 400px;
border: 1px black solid;
position: relative;
}
#image-wrap {
overflow: hidden;
position: absolute;
width: 100%;
height: 100%;
top: 0;
}
#image-wrap img {
position: absolute;
top: 0;
width: 100%;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="main-wrapper">
<div id="box-wrapper">
<div id="box">
<div id="image-wrap">
<img src="http://via.placeholder.com/600x2000" />
</div>
</div>
</div>
</div>
【问题讨论】: