I'm currently working on a project which basically involves dragging the object, after which the script begins sorting the elements inside the parent DIV and when dropped, the dragged object should return to the "placeHolder's" position.
Well everything works fine, but the last part. I've used both setTimeout and setInterval to try to make smooth animation, but with no luck.
In case of setTimeout, the released object moves too slow, even when the delay is set to 10ms.
In case if setInterval, the object moves at first slowly then makes "jumps" to the target. I've already figured out the jumps part (why it makes jumps), but still can't make smooth animation.
Here is the code after the object is released
So is there a way to make smooth transition using setInterval or a method alternative to setTimeout?
If anything is unclear about the code, I'll try to explain it more simply.
Well everything works fine, but the last part. I've used both setTimeout and setInterval to try to make smooth animation, but with no luck.
In case of setTimeout, the released object moves too slow, even when the delay is set to 10ms.
In case if setInterval, the object moves at first slowly then makes "jumps" to the target. I've already figured out the jumps part (why it makes jumps), but still can't make smooth animation.
Here is the code after the object is released
Code:
objT = parseInt(obj.style.top);
objL = parseInt(obj.style.left);
// in this case [b]def1[/b] is equal to =>
def1 = parseFloat(objT/objL);
//I'm dividing objT by objL to get the number which the script needs to move the object diagonally
function clearing() {
if ((objT>0 && objL>0) && objT>objL) {
objT-=def1;
obj.style.top = objT + "px";
objL-=1;
obj.style.left = objL + "px";
if (parseInt(objL) <= 0) {obj.style.top = 0 + "px";}
var t1 = setInterval(function() {
clearing();
if (objT===0 || objL===0) {
clearInterval(t1);}
},500);
}
So is there a way to make smooth transition using setInterval or a method alternative to setTimeout?
If anything is unclear about the code, I'll try to explain it more simply.