gpt4 book ai didi

javascript - Jquery计算动画后div的位置

转载 作者:行者123 更新时间:2023-11-30 13:38:23 25 4
gpt4 key购买 nike

嘿,我有一个通过 jquery 动画移动的 div,我正在尝试计算该 div 的位置。该位置是在点击时计算的,但随后计算的是动画之前的位置,而不是动画之后的位置。

Sooo 基本上我将如何让动画发生,然后计算位置并隐藏适当的按钮?

这是我目前所拥有的示例。除了在动画完成之前计算的 var galleryItemLeft 之外,它实际上就在那里。 http://www.ehbeat.com/test/

<script type="text/javascript">
$(document).ready(function(){

//Check width of Gallery div
var galleryWidth = $("#Gallery").innerWidth();

//Check width of GalleryItem
var galleryItemWidth = $(".GalleryItem").innerWidth();

$('.MoveRight').hide();

$(".MoveRight").click(function(){
$(".GalleryItem").animate({"left": "+=100px"}, "slow");
$(".GalleryItem2").animate({"left": "+=140px"}, "slow");
});

$(".MoveLeft").click(function(){
$(".GalleryItem").animate({"left": "-=100px"}, "slow");
$(".GalleryItem2").animate({"left": "-=140px"}, "slow");
});

$(".Controls").live("click", function() {
position = $(".GalleryItem").position();
galleryItemLeft = position.left;

if(galleryItemLeft >= "0") {
$('.MoveRight').hide();}
else{
$('.MoveRight').show();
}

if(galleryItemLeft <= galleryWidth - galleryItemWidth) {
$('.MoveLeft').hide();}
else{
$('.MoveLeft').show();
}
});

});
</script>

最佳答案

.animate() 允许您在动画完成后有一个回调函数。

例如。

$('#clickme').click(function() {
$('#book').animate({
opacity: 0.25,
left: '+=50',
height: 'toggle'
}, 5000, function() {
// Animation complete. do stuff here
});
});

要找到 div 的位置,只需执行以下操作:

var leftPos = $('#mydiv').css('left');

关于javascript - Jquery计算动画后div的位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3607175/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com