Definition and usage of ES0en.setInterval of method and the difference between offsetLeft and ES4en.left
- 2020-10-31 21:37:37
Definition and usage
The setInterval() method can call a function or evaluate an expression for a specified period in milliseconds.
The setInterval() method keeps calling the function until clearInterval() is called or the window is closed. The ID value returned by setInterval() can be used as a parameter to the clearInterval() method.
Tip: 1000 ms = 1 second.
|millisec||必须。周期性执行或调用 code 之间的时间间隔，以毫秒计。|
This method executes a 1-segment program for a specified period of time. The period is measured in milliseconds.
This method will run forever if you do not close the viewer or call the clearInterval() method.
The return value is the only 1ID identifier for this method.
Stopping this timer function can be seen in the clearInterval() method 1 section.
Click to see more properties and methods for window objects.
(1).IE browser supports this method.
(2).Firefox browser supports this method.
(3).Opera browser supports this method.
(4).chrome browser supports this method.
(5).safria browser supports this method.
Here are the differences between offsetLeft and ES61en.left
offsetLeft gets the left margin relative to the parent object
left gets or sets the left margin relative to the parent object that has the location attribute (position is defined as relative)
If position of the parent div is defined as relative and position of the child div is defined as absolute, then the value of style.left of the child div is the value relative to the parent div,
This is the same as offsetLeft except that:
1. style. left returns a string, such as 28px and offsetLeft returns a value of 28. If you need to calculate the value obtained,
offsetLeft is more convenient.
style.left is read-write and offsetLeft is read-only, so to change the position of div, you can only modify style.left.
3. The value of ES106en. left needs to be defined in advance, otherwise the value obtained is empty. And it has to be defined in html, and I did the experiment, if it's defined in
In css, the value of ES111en.left is still empty, which is the problem I ran into at the beginning. I always failed to get the value of ES113en.left.
offsetLeft can still be obtained without defining the location of div in advance.