【发布时间】:2016-08-23 14:34:52
【问题描述】:
我想根据用户的鼠标位置向右或向左移动溢出的 div(根据窗口负载计算)。 (鼠标还在那里时的连续动画)。我有一些错误/问题。
- 在鼠标悬停时不停地向该方向移动。
- 如果我使用 animate 函数,这将与 start 和 stop 一起工作,一遍又一遍会导致动画效果不佳。
有什么想法吗?
注意:我不想使用除 jquery 之外的任何额外库。
$(window).load(function() {
var buildingsWrapper = $('#buildings'),
lastBuilding = $('.building:last');
buildingsWrapper.width(parseInt(lastBuilding.css('left')) + lastBuilding.width());
var followMouseMove = function() {
var animStarted = false;
// ok now, mouse over but this will work for just one time.
buildingsWrapper.on('mouseover', function(e) {
if(e.clientX >= $(window).width() - 100) {
var left = buildingsWrapper.css('left');
if(!animStarted) {
animStarted = true;
// will work but will stop and start again after animStarted set to false. that start / stop is not what i want.
buildingsWrapper.animate({
left: parseInt(left) - 50
}, 300, function() {
animStarted = false;
});
}
}
});
};
followMouseMove();
});
【问题讨论】:
标签: javascript jquery html animation