[solved] Swap image onmouseover help needed

here you will find only solved 1.1 Help topics

Moderator: 1.1 Moderators

[solved] Swap image onmouseover help needed

Postby MrGinger on Fri Jul 16, 2010 7:46 pm

Hi.

I have been trying to achieve a nice fading image swap onmouseover with varying degrees of success and could really do with some help.

I am fairly new to mootools and I am also restricted to using mootools 1.1 as the site is a joomla 1.5 site which is also using mootools 1.1 on other pages.

I have an image of a map and would like the image to fade into a closer view of the map when the mouse hovers over it and then fade back to the original when the mouse leaves. The way I have been trying to achieve my aim is by creating a <div> with the close up image of the map as a background, I then have the other map image within that div which fades out onmouseover and then back in onmouseout.

The problem that I have is that if I set the opacity to zero onmouseover the image fades out but then doesn't fade back in again onmouseout. If I set the opacity to 0.1 then the fade in and fade out work ok but you can still see the ghost of the original image over the top of the background image.

I am sure that there is a much more simple way of doing this but unfortunately I don't know what it is.

Any help would be most gratefully received.
:)

Here's my code.

HTML
  1.  
  2. <div class="map">
  3. <a href"#"><img src="map_far_away.jpg" border="0" alt="Location Map" width="613" height="460" class="opacity"/></a>
  4. </div>
  5.  


CSS
  1.  
  2. .map {
  3.     width: 613px;
  4.     height: 460px;
  5.     background-image: url(map_close_up.jpg);
  6. }
  7.  


SCRIPT
  1.  
  2. window.addEvent('domready',function(){
  3.         var t = $$('.opacity');
  4.         t.each(function(item){
  5.         item.setStyle('opacity', 1);
  6.                  var f = new Fx.Style (item,'opacity', {duration: 600, wait:
  7. false});
  8.                  item.addEvents({
  9.                         'mouseover': function() {
  10.                         f.start(0.1);
  11.                         },
  12.                         'mouseout': function() {
  13.                         f.start(1);
  14.                         }
  15.                 })
  16.         })
  17. });
  18.  
MrGinger
 
Posts: 4
Joined: Tue May 11, 2010 6:15 pm

Re: Swap image onmouseover help needed

Postby MrGinger on Fri Jul 16, 2010 8:26 pm

Hi,

I have found a fix.

Instead of trying to fade the opacity to 0.0, instead I have faded it to 0.01 and it all work fine and you can't see any ghosting of the original image.

Hope this helps someone else along the way.
:D
MrGinger
 
Posts: 4
Joined: Tue May 11, 2010 6:15 pm


Return to Solutions

Who is online

Users browsing this forum: No registered users and 1 guest