Home > Web Front-end > JS Tutorial > body text

JS event delayed execution description analysis_javascript skills

WBOY
Release: 2016-05-16 18:27:47
Original
1072 people have browsed it

Idea: When the user crosses, set the variable i=0;
Every 100 milliseconds i
When i==10, it is exactly 1 second. Just trigger the event.
Otherwise, use clear setInterval i is not there;
Haha. I don’t know if I described it clearly.
Code:

Copy code The code is as follows:

var delay=function(t, fn){
var i=0,
j=10,
t=(t*1000)/j,
//Divide the delay time into 10 equal parts
_this=this ,
//Solve this binding problem, so when calling the delay function, please handle this pointing to the own object
d=setInterval(function(){
i;
if(i== j){
clearInterval(d);
fn.apply(_this);
};
},t);
_this.onmouseout=function(){
clearInterval( d);
};
}

Test code:

[Ctrl A select all Note: If you need to introduce external Js, you need to refresh to execute
]
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!