Pergunta

I have created a rollover image in Dreamweaver (creative cloud) but when I preview it in live mode the images don't swap on hover.

Here is my code:

<div id="facebook"><a href="#" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('facebook','','/images/facebookover.png',1)"><img src="/images/facebookup.png"  id="facebook" /></a></div> 

and my JavaScript

function MM_swapImgRestore() { //v3.0
var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
</script>
Foi útil?

Solução

You could just use CSS hover. Javascript isn't really required:

#facebook{
 width:100px;
 height:100px;
 background-image:url('image1.jpg');
}
#facebook:hover{
 background-image:url('image2.jpg');
}

Your HTML:

<div id="facebook">Text here</div>

Working example: http://jsfiddle.net/NRFQ5/

Outras dicas

If you like transitions, just add this to your style:

#facebook{
  transition: background-image 0.5s ease;
  -moz-transition: background-image 0.5s ease;
  -webkit-transition: background-image 0.5s ease;
 ...
}
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top