简体   繁体   English

将数组的(this)元素移到末尾

[英]Move (this) element of an array to the end

I have some html elements that i want to move when clicking on them using jQuery. 当我使用jQuery单击它们时,我有一些html元素要移动。 I've tried this but it didn't work 我已经尝试过了,但是没有用

var element = $('.picAll');
var arr = jQuery.makeArray(element);

arr[3].animate({"margin":"90px 0 0 35%", "z-index":"1"});
arr[2].animate({"margin":"35px 0 0 20%", "z-index":"4"});
arr[1].animate({"margin":"55px 0 0 25%", "z-index":"3"});
arr[0].animate({"margin":"75px 0 0 30%", "z-index":"2"});

$('.picAll').click(function() {
element(this).push();
});

I'm still beginner so i'm sorry for the bad code... 我仍然是初学者,因此对代码错误感到抱歉...

Push element to the end of array 将元素推到数组的末尾

 var b = $("b").get(); b.push(b.shift()); $("body").append( b ); // `b` or `$(b)` 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <b>a</b><b>b</b><b>c</b> 

Set / Store custom animation properties 设置/存储自定义动画属性

Store your Object literal you'll later pass to the .animate() into a custom Element property (ie: anim ). 存储您的Object文字,您将在稍后将.animate()传递到自定义 Element属性(即anim )中。
On element click simply recall it's property. 在元素上单击,只需回顾其属性即可。
PS: note that you cannot animate z-index ... but here you go: PS:请注意,您不能为z-index设置动画……但是您可以在这里:

 var pic = $('.picAll'); pic[3].anim = {margin:"90px 0 0 35%", zIndex:"1"}; pic[2].anim = {margin:"35px 0 0 20%", zIndex:"4"}; pic[1].anim = {margin:"55px 0 0 25%", zIndex:"3"}; pic[0].anim = {margin:"75px 0 0 30%", zIndex:"2"}; pic.click(function() { $(this).animate(this.anim); }); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <img src="favicon.ico" class="picAll"> <img src="favicon.ico" class="picAll"> <img src="favicon.ico" class="picAll"> <img src="favicon.ico" class="picAll"> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM