0

I'm using the following function to create an image loop on mouse-over. (I don't remember where I scavenged the code, but I didn't write it myself)

Script:

function zxcCycle(zxcimg,zxcary,zxcdly,zxcindex){
     if (!zxcimg.srtimg) zxcimg.srtimg=zxcimg.src;
     if (!zxcindex) zxcindex=0;
     zxcimg.src=zxcimg.src.substring(0,zxcimg.src.lastIndexOf('/')+1)+zxcary[zxcindex];
     zxcimg.onmouseout=function(){ clearTimeout(this.to); this.src=this.srtimg; }
     zxcindex=++zxcindex%zxcary.length;
     zxcimg.to=setTimeout(function(){ zxcCycle(zxcimg,zxcary,zxcdly,zxcindex); },zxcdly);
    }

Html:

<a class="example_class" href="example.html"><img src="example00.jpg" onmouseover="zxcCycle(this,example_var,160);"/></a>

The image loop works perfectly. It starts on mouse-over, and stops on mouse-out. However, I'm using the same image as a link to another page – and once I visit that page, and press the "show previous page" arrow on Safari (to go back to the page with the image loop), the loop is still going.

So how do I make this not happen? I've tried using mouse-out events, and onload functions, but I can't seem to get it to work.

Thanks in advance!

mcm
  • 41
  • 3
  • 1
    It sounds like it's acting as expected. If you navigate from a page then go back all of your JavaScript will still execute. It's still simply retrieving your image loop page from the server. – Nathan Champion Sep 10 '20 at 13:50
  • Are you looking for some way to determine if the page was navigated away from, then back to that page again? Does the user _have_ to visit your "example.html" link for your mouse over to disable or will any redirect work? – Nathan Champion Sep 10 '20 at 13:53
  • 2
    https://stackoverflow.com/a/43043658/10633285 may help if that's the case. – Nathan Champion Sep 10 '20 at 13:54
  • @NathanChampion You are spot on Nathan – thank you so much! This is exactly what I needed! I did get a double-load from the answer you linked to, but I found a solution which didn't give me the double-load, further down the page: https://stackoverflow.com/a/56851042/1474845 Again, thank you! – mcm Sep 10 '20 at 16:23
  • Actually @NathanChampion, the "solution" I found further down the page, broke my image-loop (as in, not working at all), so I implemented the solution you linked to. And it works! But it has this weird double-load, which doesn't look very nice. Do you know of a way of getting rid of this? (it was mentioned a lot in the page you linked, but didn't have a solution) – mcm Sep 10 '20 at 16:49

0 Answers0