Jquery count hover event
If you want to keep a separate counter for each agreed item, follow these steps:
jquery('.mylink').mouseover(function(){
var $this = $(this);
var count = parseInt($this.data('count'), 10) + 1;
$this.data('count', count);
});
Then you can get a counter for each item using $(selector).data('count').
Edit: Fixed a stupid bug.
If you want to know how many seconds you soared over an element, try this:
$('.mylink').hover(
//mouseover handler
function(){
//record the current time
$(this).data( 'start', new Date().getTime() );
},
//mouseout handler
function(){
//grab the end time
var end = new Date().getTime();
//calculate the difference in seconds
var hoverTime = ( end - $(this).data('start') )/1000;
//use the result
alert( hoverTime.toFixed( 2 ) );
}
);
calling this function ...
jquery('.mylink').hover(function(){
start(true)
});
function start(isStarted, index){
if(!index){
index = 0;
}
if(isStarted) {
started[index] = true;
counter[index] =0;
}
if(started[index] && true) {
counter[index] += 1;
timer = setTimeout("start(false," + index + ")",1000);
}
}