我只掌握HTML和CSS的基本知识,并通过谷歌广泛地试图找到这个问题的答案 - 这一切似乎都指向JavaScript和/或jQuery.我试过了,我无法让它发挥作用.
我有一个音频文件,当我的网站加载时开始播放.我想设置一个特定的起始音量,以便我的访客在音量很高时不会心脏病发作.
这就是我所拥有的:
HTML:
CSS:
#bgAudio { position:fixed; z-index:1000; width:250px; }
JavaScript的:
backgroundAudio=document.getElementById("bgAudio"); backgroundAudio.volume=0.5;
任何帮助将不胜感激!
您没有获得该元素,并且错误显示在控制台中
无法将属性'volume'设置为null
将脚本移动到</body>
标记之前,或执行:
window.onload = function() { var backgroundAudio=document.getElementById("bgAudio"); backgroundAudio.volume=0.5; }
编辑:
没有什么比禁用右键点击更烦人了,但无论如何,这就是你拥有的
;(function($){ mySong=document.getElementById("bgAudio"); mySong.volume=0.2; setVolume = function(bgAudio,vol) { sounds[bgAudio].volume = 0.33; } })(jQuery);
现在改成它
jQuery(function($) { $("#bgAudio").prop("volume", 0.2); window.setVolume = function(bgAudio, vol) { sounds[bgAudio].volume = vol; } });