Jump to content

starting again cleared Interval


Matej

Recommended Posts

Hi i have script

<p id="lol" onmouseover="zmena()" onmouseout="sopka()">ahoj</p>
var x=document.getElementById("lol");var start;var zacni=0;function zmena(){if(x.innerHTML=="ahoj"){x.innerHTML="cau"}else if(x.innerHTML=="cau"){x.innerHTML="hi"}else if(x.innerHTML=="hi"){x.innerHTML="ahoj"} zacni=1;} function sopka(){x.innerHTML="ahoj";zacni=0} function timing(){if(zacni){start=setInterval(function(){zacni()},1000);}else{clearInterval(start);}} window.onload=timing;

I wanna start again chaning of changing innerHTML on mouseover , but it doesnt work can someone help?

Edited by Matej
Link to comment
Share on other sites

it's hard to read your code. can you indent and format it a little bit?

 

also, are you checking for errors? what is happening? does anything change? please be specific.

Link to comment
Share on other sites

You mean like this?

<p id="lol">ahoj</p>
var inner = ["ahoj","cau","hi"],int_ID; function startCycle(){  var i=0, self = this,      looper = function(){    i= (++i%inner.length);    self.innerHTML = inner[i];  };  int_ID = setInterval(looper,1000);} function endCycle(){    this.innerHTML = inner[0];    clearInterval(int_ID); } window.onload = function(){  var x=document.getElementById("lol");  x.onmouseover = startCycle;  x.onmouseout = endCycle;};
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...