|  | Posted by Jonathan N. Little on 03/17/06 16:12 
Aaron Freeman wrote:> I have a javascript swap image funciton that's called when a user clicks
 > on an image wrapped by an anchor. The anchor points to "#", but the
 > problem is  that the image is below the fold, and when the user clicks
 > on the image, the image swaps but the page links to "#" and scrolls the
 > page to the top.
 
 First of all why are your using a 'A' (link) that goes nowhere? Do you
 just want to do some sort of a image swap, if so there are other ways to
 to do an image swap on mouse-overs. Generally when the cursor changes to
 the 'hand' folks expect i to be a link that takes you somewhere. Without
 a URL is is hard to say in your case but it seems like your are
 "painting a false 'door' on a solid brick wall like a Candid Camera stunt"
 
 > So it looks like:
 >
 > <a href="#" onClick="function()"><img src="image.gif"></a>
 
 To prevent the link from traveling the onclick function needs to return
 FALSE. Of course this only works IF JavaScript is enabled, else your
 have the same problem, the browser looks for a nonexistent anchor so
 moves to the top of the page. One way to stop this is to provide a valid URL
 
 function myFunction(){
 ...
 return false; // <-important don't forget
 }
 
 <a href="#StayHere" onclick="return myFunction()">
 <img id="StayHere" src="image.gif">
 </a>
 
 Where 'myFunction' returns FALSE else you have to added it to the
 onclick "myFunction(); return false". Then the fall back if the user has
 disabled the link points to where you are and the page does not scroll.
 
 >
 > If I place the onClick on the image itself, the swap will work without
 > jumping the page, but the cursor won't change to indicate a "hot" image.
 
 Again would help to know what your need a "hot Zone" indication for.
 >
 > Is there an easy solution here?
 
 --
 Take care,
 
 Jonathan
 -------------------
 LITTLE WORKS STUDIO
 http://www.LittleWorksStudio.com
  Navigation: [Reply to this message] |