jQuery动画回到原来的位置
问题描述:
我有一个网站我正在研究,有几个absolutelty定位divs,我需要调整点击,这些将填补divs在容器中。问题是我怎么让他们切换回到原来的位置(顶部,左侧),这是不同的。jQuery动画回到原来的位置
$(".work-item .toggle").toggle(function() {
$(this).parent().animate({ height: '430', width: '930', top: '0', left: '0' }, 750);
},
function() {
var pos = $(this).parent();
var position = pos.position();
$(this).parent().animate({ height: '150', width: '200', top: position.top, left: position.left }, 750);
});
尝试了上述,但它获得了新的位置不是原来的。
在此先感谢。
PVS
答
可以使用,当第一次加载页面$.data()
并在以后使用它,喜欢这家店的位置:
$(".work-item .toggle").each(function() {
$.data(this, 'position', $(this).parent().position());
}).toggle(function() {
$(this).parent().animate({ height: '430', width: '930', top: '0', left: '0' }, 750);
}, function() {
var position = $.data(this, 'position');
$(this).parent().animate({ height: '150', width: '200', top: position.top, left: position.left }, 750);
});
此存储.position()
每个元素的父绑定之前,则在稍后动画时使用它。
谢谢尼克!作品一种享受。 – 2010-10-04 11:58:12