Forum Moderators: open

Message Too Old, No Replies

Help very needed)

Icon rotation system

         

orion_rus

6:02 pm on Feb 28, 2005 (gmt 0)

10+ Year Member



Hello world i have a icon rotation system it works perfectly for one rotation. But i need widespread it to any number of icons.
Now the code is following:
<html>
<head>
<title></title>
<meta/>
<script type="text/javascript">
var elem;
function rotateimage(elem,imagelist,current,next)
{
alert(current);
parseInt(current);
imagearray=imagelist.split(",");
imagelength=imagearray.length--;
elem.src=imagearray[current];
if (next=='next') {
current--;
lastevent=function () {rotateimage(this.parentNode.parentNode.firstChild,imagelist,current,"previous");}
elem.parentNode.lastChild.firstChild.onclick=lastevent;
elem.parentNode.lastChild.firstChild.style.display='block';
current++;
if (current==imagelength)
{elem.parentNode.lastChild.lastChild.style.display='none';

} else {
current++;
newevent=function () {rotateimage(this.parentNode.parentNode.firstChild,imagelist,current,"next");}
elem.parentNode.lastChild.lastChild.onclick=newevent;
}
}
if (next=='previous') {
current++;
lastevent=function () {rotateimage(this.parentNode.parentNode.firstChild,imagelist,current,"next");}
elem.parentNode.lastChild.lastChild.onclick=lastevent;
current--;
elem.parentNode.lastChild.lastChild.style.display='block';
if (current==0)
{elem.parentNode.lastChild.firstChild.style.display='none';
} else {
current--;
newevent=function () {rotateimage(this.parentNode.parentNode.firstChild,imagelist,current,"previous");}
elem.parentNode.lastChild.firstChild.onclick=newevent;
}}
}

</script>
</head>
<body>
<div><img src="" />
<div><img src="images/icons/arrowdown.gif" style="float:left" onclick=rotateimage(this.parentNode.parentNode.firstChild,"images/icons/arrow.gif,images/icons/arrowdown.gif,images/icons/arrowup.gif,images/icons/arrowdownh.gif",1,"previous") /><img src="images/icons/arrowup.gif" onclick=rotateimage(this.parentNode.parentNode.firstChild,"images/icons/arrow.gif,images/icons/arrowdown.gif,images/icons/arrowup.gif,images/icons/arrowdownh.gif",2,"next") /></div></div>
</body>
</html>

The problem is in following. Then onclick event fires it takes value from a current variable. But if i use several rotations systems current for this icon system overwriten by another currentsystem. Maybe somebody have any solutions?

cmatcme

7:43 pm on Feb 28, 2005 (gmt 0)

10+ Year Member



There are lots of onClick events and in the tos it said no "i'm giving you the code, you correct it" things.

orion_rus

8:01 pm on Feb 28, 2005 (gmt 0)

10+ Year Member



i need an idea how to fix it. I give you another example may be you give me right way
it is like follows:
<script>
function makeoutput(img,data)
{img.onclick=alert(data);}
</script>
<img1>
<div1 onclick=makeoutput(img1,"hi")>
<div2 onclick=data="big" />
if you click first to a div1 and then to img 1 you have an alert with ('hi')
but if you click on div1 and then on div2 and only then on img you have an alert with('big') but i need to make an hi ouput i watching an idea how to fix "hi" in a img1.onclick, even if data is changes
I hope i was clear)