PDA

View Full Version : Varied Use of Script



Webiter
11-20-2012, 05:50 PM
1) Script Title: Dynamic Drive DHTML Scripts- Image Swap and HTML5 audio effect

2) Script URL (on DD): http://www.dynamicdrive.com/dynamicindex15/domroll2.htm

3) Describe problem: Could this script run a sound automatically when a web page loads?

bernie1227
11-20-2012, 08:30 PM
You could modify it to play on page load, but it would be a lot easier t0 just use an audio element (http://www.w3.org/wiki/HTML/Elements/audio). You can then make it run on page load by just doing something like:


<audio src="audio/sample.mp3" autoplay>
<!-- your audio files -->
</audio>

ddadmin
11-20-2012, 08:45 PM
Bernie is right, though going back to your original request, you can get the button to automatically play its sound when the page loads by first giving the button element an ID attribute to identify it, then following it, artificially triggering the event handler that plays the sound. For example:


<img id="test" src="original.jpg" data-srcover="over.jpg" data-soundover="whistle.mp3, whistle.ogg, whistle.wav">

<script>

$(window).bind('load', function(){ // when page loads
$('#test').trigger('mouseover') // trigger "mouseover" event of #test element
})

</script>

If you button uses the data-sounddown attribute to play a sound, then change "mouseover" inside the script that follows to "mousedown" instead.