Good Morning,
I want to insert a jQuery fadeIn()
and fadeOut()
on my site. Theoretically, the code I have works, but there is something what I dont like.
The fadeIn()
is triggered by moving the mouse over a mapped area of an imagemap
. A hidden div
is faded in, overlaying the imagemap. When leaving the mapped area, the overlaying div is faded out.
What is happening is, that de fadeIn()
only starts when the mouse comes to rest over the mapped area, but not by hovering over it. So, in order to trigger the effect, the mouse needs to enter the mapped area and come to complete rest.
What I want instead is that de fadeIn()
starts as soon as the mouse enters the mapped area, no matter how long it stays there.
Here an exerpt of my code
//JAVASCRIPT
//PRELOAD THE SOURCEIMAGE
original = new Image(655, 338);
original.src = "imagenes_png/bosque_mapa.png";
//PRELOAD THE IMAGES FOR MOUSEOVER
azulH = new Image(655, 338)
azulH.src = "imagenes_png/azul_mouse_h.png";
verdeH = new Image(655, 338)
verdeH.src = "imagenes_png/verde_mouse_h.png";
//LOAD THE DOM BEFORE JS FILLS IT WITH IMG (HIGHLIGHT)
$(document).ready(function() {
document.getElementById("verdeH").appendChild(verdeH);
document.getElementById("azulH").appendChild(azulH);
});
//JQUERY
//jQUERY FADEIN
$(document).ready(function() {
$(function() {
$("#verdeA").mouseenter(function() {
$("#verdeH").stop().fadeIn("fast");
});
$("#verdeA").mouseleave(function() {
$("#verdeH").stop().fadeOut("fast");
});
$("#azulA").mouseenter(function() {
$("#azulH").stop().fadeIn("fast");
});
$("#azulA").mouseleave(function() {
$("#azulH").stop().fadeOut("fast");
});
});
});
Any ideas how to accomplish this? If HTML Code is needed, I can provide it!
And here the HTML
<!-- LOAD OVER(!) THE IMAGEMAP WITH DIV FOR POSITIONING-->
<div style="position:relative" width="655" height="338">
<!-- HIDDEN PRELOADED IMAGES FOR HIGHLIGHT-->
<div id="azulH" style="display:none; position:absolute" width="655" height="338"></div>
<div id="verdeH" style="display:none; position:absolute" width="655" height="338"></div>
<!-- INSERT THE PICTURE -->
<img name="bosque" id="bosque" src="imagenes_png/bosque_mapa.png" width="655" height="338" border="0" usemap="#bosque_m" alt="Bosque con animales" />
<!-- CREATE THE MAP -->
<map name="bosque_m" id="bosque_m">
<area shape="poly" coords="605,304,608,301,613,300,617,302,618,308,617,313,618,315,620,317,624,318,628,318,631,318,634,320,635,326,634,331,629,334,626,337,625,339,602,338,602,334,604,330,608,326,609,320,608,315,606,311,604,308,605,304"
id="verdeA" alt="¡Un animal ocultado!" />
<area shape="poly" coords="442,233,447,233,451,235,454,238,456,242,457,246,463,247,468,249,472,251,474,254,470,255,465,253,460,252,456,252,454,253,450,253,445,251,441,247,439,244,439,239,442,233"
id="azulA" alt="¡Un animal ocultado!" />
</map>
</div>
A Fiddle of the thing http://jsfiddle.net/n96070kd/