Javascript 如何淡出图像,然后使其出现在jquery中的另一个位置上?
我的图像在某个div,它的z指数是最高的 当我点击某个东西时,我希望它淡出,然后淡入另一个指定位置。下面是另一个类的图片:)这是一个“aaa”类 我是这样做的:Javascript 如何淡出图像,然后使其出现在jquery中的另一个位置上?,javascript,jquery,Javascript,Jquery,我的图像在某个div,它的z指数是最高的 当我点击某个东西时,我希望它淡出,然后淡入另一个指定位置。下面是另一个类的图片:)这是一个“aaa”类 我是这样做的: $('img.classy').fadeOut(); $('img.classy').css('top',$(el).find('img.aaa:last').height()+60); $('img.classy').fadeIn(); 它嵌入到单击事件中。当我运行它并单击
$('img.classy').fadeOut();
$('img.classy').css('top',$(el).find('img.aaa:last').height()+60);
$('img.classy').fadeIn();
它嵌入到单击事件中。当我运行它并单击该区域时,img.classy首先更改它的位置,然后在新位置上淡出淡入。我显然想这样做:淡出->不可见时改变位置->新位置上的淡入淡出。怎么做?这样可以:
$('img.classy').fadeOut(function() {
$('img.classy').css('top',$(el).find('img.aaa:last').height()+60);
$('img.classy').fadeIn();
});
由于
fadeOut
和fadeIn
是异步函数,脚本将继续运行,这些函数会导致img
立即更改其位置。您需要等待,直到fadeOut完成。我为您添加了一个回调函数
$('img.classy').fadeOut('slow', function() {
$(this).css('top',$(el).find('img.aaa:last').height()+60);
$('img.classy').fadeIn();
});
这将克隆img,将其删除并将其附加到其他包装器:
.aaa {position: relative}
.classy {position: absolute; right:0; top:0}
$('img.classy').fadeOut(
cloned = $(this).clone(true);
$(this).remove();
$("img.aaa:last").append(cloned);
$(".classy").fadeIn();
);
非常感谢。正如你所看到的,我正在手动定位我的图像,也许你知道如何定位我的图像以显示在指定的图像下,正好在它的右下角?