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