Home > front end >  How about the offsetLeft put it as a parameter to the function
How about the offsetLeft put it as a parameter to the function

Time:09-18

This is I began to do, no problem
Btu. Onclick=function () {
Move (box, 800, 10);
};
Function move (obj, target, speed) {//obj is called event object, target, transfer the longest position, the sliding speed transfer positive and negative value (to the left or judgment)
//with incoming obj and time attribute, makes the timer only work on their own div, not affected by other div
ClearInterval (obj. Time);//remove the last invocation timer
//timer
Var initial=parseInt (obj. offsetLeft ).
If (initial & gt; Target)
{speed=- speed; }

Obj. Time=setInterval (function () {
//get the current value left
Var oldvalue=https://bbs.csdn.net/topics/parseInt (obj. offsetLeft ).
Var newvalue=https://bbs.csdn.net/topics/oldvalue + speed;

Below is I change, bosses give directions
Btu. Onclick=function () {
Move (box, Left , 800, 10);
};
The function move (obj, attr , target, speed) {

ClearInterval (obj. Time);//remove the last invocation timer

Var initial=parseInt ( obj. Offset + attr ).
If (initial & gt; Target)
{speed=- speed; }

Obj. Time=setInterval (function () {
//get the current value left
Var oldvalue=https://bbs.csdn.net/topics/parseInt ( obj. Offset + attr ).
Var newvalue=https://bbs.csdn.net/topics/oldvalue + speed;

Just want to use offset attribute, no matter is behind the Left or Top, Width, Height can be passed as a parameter in the function
  • Related