/    Sign up×
Community /Pin to ProfileBookmark

Repeat function each tot sec

Hello,

I need to execute a function each ‘tot’ seconds.

Particularly, I need to use the [B]onmousemove[/B] event and instead of calling a function on each mouse movement I need to call it on each movement just if it happens 1 sec (or tot secs) after the previous calling…

It seems easy but I’m not able to create such loop with control…

may you help me?

to post a comment
JavaScript

6 Comments(s)

Copy linkTweet thisAlerts:
@KorNov 09.2007 — Sounds confusing to me... can you detail a little bit your aim?
Copy linkTweet thisAlerts:
@embraceauthorNov 09.2007 — Of course I can.

I want to get some data about mouse movement and store them in a database. However as my customers got so many visitors I can not store each mouse movement.

So I decided to get just 40 different positions for each page and to get each position every second (or every two seconds).

To realize that I was trying to 'delay' and control the onmousemove function with a [B]loop[/B] and an [B]if[/B] control ... but I get no results.

I need ideas on how to realize my idea ?
Copy linkTweet thisAlerts:
@KorNov 09.2007 — To "delay" the calling of a function, you may use setTimeout() method:

http://www.w3schools.com/js/js_timing.asp
Copy linkTweet thisAlerts:
@embraceauthorNov 09.2007 — Yep I used setTimeout in many cases but in this particular I don't have the result I need.

In fact setTimeout just wait to execute the command but does not check if an other command is issued less the one second before...I just get the result that each mouse movement is elaborated after tot seconds but I don't need this.

I don't just need to delay, I need to take informations each tot secs.

I also tried with setInterval, but I still can not control it because onmousemove sends me to many calls
Copy linkTweet thisAlerts:
@KorNov 09.2007 — Let me see: You want to trigger a function [B]only once[/B], first time when user rolls over an element, then you need a certain operation to repeat each "tot seconds", but you don't want to call again that function next time when user rollon again that element?
Copy linkTweet thisAlerts:
@KorNov 09.2007 — Like this?:
<i>
</i>&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"&gt;
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Untitled Document&lt;/title&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"&gt;
&lt;meta http-equiv="Content-Style-Type" content="text/css"&gt;
&lt;meta http-equiv="Content-Script-Type" content="text/javascript"&gt;
&lt;script type="text/javascript"&gt;
var i=0;
function killThisEvent(obj){
obj.onmouseover=function(){return false}
writeSomething()
}
function writeSomething(){
document.getElementById('mydiv').innerHTML=i
i++
setTimeout('writeSomething()',2000)
}
&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;div onmouseover="killThisEvent(this)"&gt;roll over&lt;/div&gt;
&lt;br&gt;
&lt;div id="mydiv"&gt;&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;
×

Success!

Help @embrace spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.4,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...