我不太清楚你想要实现什么,但没有“对象被 jquery 通过动画操作”的事件处理程序。只有一种方法可以检查元素是否正在动画:
if($(elemement).is(':animated')) {/*do something*/}
您所指的坐标是什么,是图像的左侧和顶部offset() 位置吗?在 jQuery animate() 中有一个 step 函数,一个在动画的每一步都会触发的回调函数。如果图像的当前位置大于或小于,这可以帮助您检查并设置条件,但不要使用等于 '==' 不能保证在某个步骤上将返回等于您的值正在比较。
在 jsfiddle 上测试它。
我制作了一个简单的滑块,它可能与您正在尝试做的事情相似,并且可以帮助您开始工作。
html 标记:
<div id="sliderWindow">
<img class="slideshowImages" src="" />
<img class="slideshowImages" src="" />
<img class="slideshowImages" src="" />
</div>
CSS:
#sliderWindow {
background:#333;
position:relative;
width:300px;
height:100px;
margin-left:100px;
overflow:hidden;
}
.slideshowImages {
position:absolute;
left:100%;
opacity:1;
}
jQuery:
//function that calculates the left value to center the img
function center(el) {
return ($('#sliderWindow').width() / 2) - (el.width() / 2)
}
//center the first img
var $first = $('.slideshowImages:first');
$first.css({'left': center($first)});
//set the duration of animate
var duration = 1000;
$('.slideshowImages').click(function () {
var $this = $(this),
//distance traverse from current position until completely hidden
distance = $this.width() + center($this),
//get the speed
speed = distance / duration,
/*calculate the duration if it's only to travel
half it's left margin at the same rate
*/
halfway = (center($this) / 2) / speed;
$this.animate({
'left': -Math.abs($this.width()) //hide on the left
}, duration);
//halfway, trigger animate on the next img
setTimeout(function () {
$this.next().animate({
left: center($this.next())
}, duration);
}, halfway);
});
这里是jsfiddle。