Tags:

function pointerMove(elm){

var p = $(elm);

var offset = p.offset();

var vleft = offset.left+"px"

$(elm).animate({bottom: "+=15px"}, vleft);

$(elm).animate({bottom: "-=15px"}, vleft, function(elm){

console.log(elm);

pointerMove(elm);

});

}

ผมเขียน โคดไว้สำหรับรันภาพหลายๆ ตัวครับแต่มันไม่ยอมส่งค่า elm ในส่วนของ
call back ไม่รู้ว่าทำไม มีข้อเสนอมั้ยครับ

Get latest news from Blognone
By: soginal
AndroidIn Love
on 26 August 2012 - 12:29 #464019
soginal's picture

Complete Function

If supplied, the complete callback function is fired once the animation is complete. This can be useful for stringing different animations together in sequence. The callback is not sent any arguments, but [this] is set to the DOM element being animated. If multiple elements are animated, the callback is executed once per matched element, not once for the animation as a whole.

By: Wai on 27 August 2012 - 14:28 #464350

เปลี่ยนบรรทัดนี้
$(elm).animate({bottom: "-=15px"}, vleft, function(elm){

ไปเป็น
$(elm).animate({bottom: "-=15px"}, vleft, function(){

ตัด elm ออกไป เนื่องจาก elm มีประกาศไว้ด้านนอก anonymous function อยู่แล้ว เมื่อประกาศซ้ำอีกครั้งใน anonymous function จะทำให้ error ครับเนื่องจากขอบเขตของตัวแปรมันขัดแย้งกันครับ และ anonymous function ที่สร้างขึ้นสามารถเรียกใช้ตัวแปรที่อยู่นอกขอบเขตได้เลยครับ (มีขอบเขตการมองเห็นตัวแปร เท่ากับฟังก์ชั่น pointerMove + ตัวแปรที่ประกาศภายใน anonymous function)

By: oscool
iPhoneWindows PhoneAndroidBlackberry
on 30 August 2012 - 17:55 #466210

$(elm).animate({bottom: "-=15px"}, vleft, function(elm){
console.log($(this));
pointerMove($(this));
});