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:
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:
]
Statement: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