onmouseover sound

Discussion corner for Developers of Serendipity.
Post Reply
bdconnolly
Regular
Posts: 140
Joined: Tue Apr 04, 2006 9:37 pm

onmouseover sound

Post by bdconnolly »

Something trivial. I am just looking to add a little snap sound when mouseover menu items. Found a few javascripts but none validate.

Thoughts?

Thanks.

BC
bdconnolly
Regular
Posts: 140
Joined: Tue Apr 04, 2006 9:37 pm

Post by bdconnolly »

Posted here because I saw many asking for it. Sorry if this should be somewhere else.

<script language="javascript" type="text/javascript">
<!--
function play(soundobj)
{
var thissound = eval(soundobj);
thissound.CurrentPosition=0;
thissound.play();
}

function stop(soundobj)
{
var thissound = eval(soundobj);
thissound.stop();
}
//-->
</script>

<object name="lastdance" type="application/x-mplayer2" width="0" height="0" data="lastdance.mp3">
<param name="filename" value="lastdance.mp3" />
<param name="autostart" value="false" />
</object>

<a href="#" onmouseover="play('lastdance')">Play Sound</a>

<a href="#" onmouseover="stop('lastdance')">Stop Sound</a>

Explanation:

Embed the JavaScript in the body of your page. Embed the object also within the body, as many sounds as you want, be sure and label them accordingly within the name attribute as well as when you call the functions.

Will work with any kind of sound file that Windows Media Player supports. Unfortunately, will only work if the user has Windows Media Player, but should be Cross-browser and XHTML Transitional Compliant.
roberts
Posts: 1
Joined: Tue May 29, 2007 5:06 pm

Post by roberts »

Great post, it is useful, yes, just but only work if the user has Windows Media Player. :wink:
Post Reply