【发布时间】:2014-10-08 23:16:18
【问题描述】:
我有一个简单的 jQ 脚本:
- 设置宽度/高度的容器
- 风景图片(可以更大或 小于容器)
- 当用户将鼠标悬停在图像上时,它会平移 (没有点击/拖动)直到它到达终点
将 img 向左移动的等式如下: -1(相对鼠标位置)*(img width)/(container width)
这很好用,但它会在鼠标到达 img 末尾时留下一个空格。
$("figure img").mousemove( function (e) {
var a = $(this).closest("figure"),
b = $(this).width(),
c = a.width(),
d = (e.clientX - a.offset().left);
$(this).css({
left: -1*(d*b/c)
}, 100);
});
有人可以帮忙吗?一旦鼠标到达终点,我希望 img 与容器的右侧完全对齐。
【问题讨论】:
标签: javascript jquery html css image