OK..
I have this site: http://stephaniie.com/_testlab/beta1/
{ Full html code: http://pastebin.com/u4HpxcB2 }
If you scroll down , on the right , there is Knight next to a Tower..
- If you move your mouse from his right side.. an larger image of the Knight pop up.
- And If you move the mouse closer to him an animation starts and he starts "talking"
This is made by some pretty easy coding.
->
For the KNIGHT-IMAGE to appear this CSS and Javascript is used:
Original Source: http://clba.nl/sitepoint/img-hover-demo-js1.htm
<style>
#img2{
position: absolute;
top: 1400px;
left: 50px;
display: none;
}
#img1:hover + #img2 {display:block}
</style>
<script>
var img1 = document.getElementById("sol,
img2 = document.getElementById("img2");
img1.onmouseover = function(){
img2.style.display = "block";
}
img1.onmouseout = function(){
img2.style.display = "none";
}
</script>
For the music to start playing a PlaySound/StopSound Javascript is used.
Original Source: Javascript play sound on hover. stop and reset on hoveroff
<script>
function PlaySound(soundobj) {
var thissound=document.getElementById(soundobj);
thissound.play();
}
function StopSound(soundobj) {
var thissound=document.getElementById(soundobj);
thissound.pause();
thissound.currentTime = 0;
}
</script>
Question: How can I combine these two functions when I hover the Knight?
For HTML on the website I use "< map >" and "< area >" to make an Image map.
Code is:
<map name="map12" id="img_id12">
<area class="youtube" coords="1497,52,1588,128" shape="rect" href="http://www.youtube.com/embed/GPbUA6dCR8k" style="outline:none;"
onmouseover="if(document.images) document.getElementById('img_id12').src= 'assets/images/text/day/12.gif';"
onmouseout="if(document.images) document.getElementById('img_id12').src= 'assets/images/no-text/day/12.gif';" />
<area class="youtube" coords="3878,24,3957,96" shape="rect" href="https://www.youtube.com/embed/skV-q5KjrUA" style="outline:none;"
onmouseover="if(document.images) document.getElementById('img_id12').src= 'assets/images/text/day/12solaire-ani.gif'; PlaySound('solaire'); "
onmouseout="if(document.images) document.getElementById('img_id12').src= 'assets/images/no-text/day/12.gif'; StopSound('solaire'); PlaySound('solaire-stop');" />
<area id="sol" coords="3890,23,3970,100" shape="rect" style="outline:none;" />
</map>
The Only thing I want is too add a image appear function to my <"area"> code. So,
<img id="img2" src="solaire.gif" alt="" style="display: none;">
becomes this when "mouseover function" is activated.
<img id="img2" src="solaire.gif" alt="" style="display: block;">
Comment: As you can see in the code Above and on the website I'm able to use the image-hover and play/stopsound but not at the same time. Is there a way to use both script at the same time? If you wonder what the "onmouseover="if(document.images) document.getElementById('img_id12').src= 'assets/images/text/day/12solaire-ani.gif';" does. Its for changing the background to another one using an ID.
<img src="assets/images/no-text/day/12.gif" usemap="#map12" id="img_id12" class="first" />
I tried to add this "image appear/hide" script to "mouseover" in the map area code. Like this.
<area id="sol" class="youtube" ...
onmouseover="if(document.images) document.getElementById('img_id12').src= 'assets/images/text/day/12solaire-ani.gif'; PlaySound('solaire'); "
</area
This works.. however the PlaySound/StopSound doesn't work anymore. However the Colorbox and changing image still works too. So the issue is adding the appear/hide image function and still have the PlaySound/StopSound function working .
Edit and more Information: Im also using two Javascript tools called Colorbox and Responsive Image Map. * Colorbox is a a jQuery lightbox script. Source: http://www.jacklmoore.com/colorbox/ * Reponsive Image Map allows image maps to be resized with screen-size. Source: http://mattstow.com/experiment/responsive-image-maps/rwd-image-maps.html
The code to use them on Index page is this.
<script>
$(document).ready(function(e) {
$('img[usemap]').rwdImageMaps();
});
$(document).ready(function(){
//Examples of how to assign the Colorbox event to elements
$(".youtube").colorbox({iframe:true, innerWidth:1024, innerHeight:576});
});
/script>
Full code for Responsive Image Map script and Colorbox is found here.
Responsive Image Map script: - Link -> http://pastebin.com/699T5kLY
Colorbox: - Link -> http://pastebin.com/Jj4SQEhu - Link -> http://pastebin.com/bErhvPFA