TOP /すぐに使えるJavaScript | BackGround Sound IE専用 | music by Sora Aonami |
---|
BGMを切り替えてボリュームも設定できます。
設定を記憶します。
<script type="text/javascript"><!-- soundsrc=new Array("swonderful.mid","furudokei.mid","araitate2.mid"); //ファイル soundtitle=new Array("ス・ワンダフル","おじいさんの古時計","恋心"); //タイトル sv=7; //初期音量 0〜10 theDay=1; //記憶日数 sw=170; //スライドバーの幅 //------------------------------------------- theName="bgm="; document.write("<bgsound id='bgs'loop='infinite' src=''>"); document.write("<form name='form1'><select name='select1'>"); for(i in soundsrc) document.write("<option value='"+soundsrc[i]+"'>"+soundtitle[i]+"</option>"); document.write("</select><input type='button'value='選曲'"); document.write("onClick='document.all.bgs.src=this.form.select1.value;selectno=this.form.select1.selectedIndex'>"); document.write("</form>"); document.write("<table vspace=0 cellspacing=0 width="+sw+"><tr onmousedown='mc=0'style='cursor:hand'>"); for(i=0;i<=10;i++) document.write("<td id='v"+i+"'onmouseover='vol("+i+")'height=16></td>"); document.write("</tr></table>"); mc=0;sc=sv; selectno=0; function vol(sv){ if(mc)return; sc=sv; s=(-(sv-10)*(sv-10)+100)*100-10000; document.all.bgs.volume=s; for(i=0;i<=10;i++){ if(i<=sv){document.all("v"+i).style.backgroundColor="#3399ff";} else {document.all("v"+i).style.backgroundColor="#cccccc";} (sv==i)?document.all("v"+i).title=sv:document.all("v"+i).title="";} } function bgm_set(){ theCookie=document.cookie+";"; start=theCookie.indexOf(theName); if(start !=-1){ end=theCookie.indexOf(";",start); theData=unescape(theCookie.substring(start+theName.length,end)); setbgm=theData.match(/[^,]+/g); sv=setbgm[1]; selectno=setbgm[0]; } document.all.bgs.src=document.form1.select1.options[selectno].value; document.form1.select1.selectedIndex=selectno; vol(sv); } function cook_set(){ setDay=new Date(); myData=selectno+","+sc ; setDay.setTime(setDay.getTime()+(theDay*1000*60*60*24)); document.cookie=theName+escape(myData)+";expires="+setDay.toGMTString(); } window.onload = function(){bgm_set();mc=1;}; document.body.onmouseup = function(){mc=1;}; window.onunload = function(){cook_set();}; document.body.onselectstart = function(){return false;}; /* himajin.moo.jp */ // --></script>