Note that there are some explanatory texts on larger screens.

plurals
  1. POMoving javascript audio into jquery
    primarykey
    data
    text
    <p>This is my first post to the forum. I am setting up an English/Thai language course website which will contain many audio files of English and Thai speech. I did a single webpage proof of concept using a mouseover/button javascript function <a href="http://www.javascriptkit.com/script/script2/soundlink.shtml">http://www.javascriptkit.com/script/script2/soundlink.shtml</a> With some mods and some inline js, this worked OK.</p> <pre><code>$(document).ready(function() { var html5_audiotypes = { "mp3": "audio/mpeg", "ogg": "audio/ogg", }; function createsoundbite(sound) { "use strict"; var html5audio = document.createElement('audio'); if (html5audio.canPlayType){ for(var i=0; i&lt;arguments.length; i++) { var sourceEl = document.createElement('source'); sourceEl.setAttribute('src', arguments[i]); if (arguments[i].match(/\.(\w+)$/i)) sourceEl.setAttribute('type', html5_audiotypes[RegExp.$1]); html5audio.appendChild(sourceEl); } html5audio.load(); html5audio.playclip = function() { html5audio.pause(); html5audio.currentTime=0; html5audio.play(); } return html5audio; } else{ return {playclip:function(){throw new Error("Your browser doesn't support HTML5 audio unfortunately")}}; } } var cn402=createsoundbite("audio/cn402.ogg", "audio/cn402.mp3"); var ry402=createsoundbite("audio/ry402.ogg", "audio/ry402.mp3"); var cn403=createsoundbite("audio/cn403.ogg", "audio/cn403.mp3"); var ry403=createsoundbite("audio/ry403.ogg", "audio/ry403.mp3"); var cn404=createsoundbite("audio/cn404.ogg", "audio/cn404.mp3"); var ry404=createsoundbite("audio/ry404.ogg", "audio/ry404.mp3"); }); </code></pre> <p>The javascript code is called by a line of html code like this:</p> <pre><code> &lt;a href="#current" class= "rollover" onclick="ry402.playclip()"&gt;&lt;/a&gt;Please don't swim by yourself&lt;/span&gt; </code></pre> <p>I want to incorporate this function and its associated variables into jquery. so that all js code is removed from the html. The first step, just getting the jquery code to work has proved a bit problematic for me. I've tried just including the js audio code in a document ready function. as shown above but this doesn't work. Any help would be much appreciated. </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload