HTML5 怎么给网页加屏幕点击声音。

html-css016

HTML5 怎么给网页加屏幕点击声音。,第1张

利用HTML5中的audio标签,播放声音,不过为了照顾IE 6-8,还是用上了bgsound。兼容所有主流浏览器(非主流不在考虑之列了)代码:<a href="#" class="fui-btn">播放</a><script>/*Play sound component*//* * profile: JSON, {src:'chimes.wav',altSrc:'',loop:false} * * setSrc: Function, set the source of sound * play:Function, play sound */if (!FUI){var FUI = {}}FUI.soundComponent=function(profile){this.profile={src:'',  //音频文件地址altSrc:'', //备选音频文件地址 (不同浏览器支持的音频格式不同,可见附表)loop:false  //是否循环播放,这个参数现在没有用上} if(profile) {$.extend(this.profile,profile) }this.soundObj=null this.isIE = !-[1,]/*这个方法是前辈大牛发明的,利用ie跟非ie中JScript处理数组最后一个逗号“,”的差异, 不过对于IE 9,这个办法就无效了,但此处正合我用,因为IE 9支持audio*/this.init()}FUI.soundComponent.prototype={init:function(){this._setSrc() },_setSrc:function(){if(this.soundObj){if(this.isIE){this.soundObj[0].src=this.profile.src }else{this.soundObj[0].innerHTML='<source src="'+this.profile.src+'" /><source src="'+this.profile.altSrc+'" />' }}else{if(this.isIE){this.soundObj=$('<bgsound volume="-10000" loop="1" src="'+this.profile.src+'">').appendTo('body')//-10000是音量的最小值。先把音量关到最小,免得一加载就叮的一声,吓到人。}else{this.soundObj=$('<audio preload="auto" autobuffer><source src="'+this.profile.src+'" /><source src="'+this.profile.altSrc+'" /></audio>').appendTo('body') }}},setSrc:function(src,altSrc){this.profile.src=src if(typeof altSrc!='undefined'){this.profile.altSrc=altSrc }this._setSrc() },play:function(){if(this.soundObj){if(this.isIE){this.soundObj[0].volume = 1//把音量打开。this.soundObj[0].src = this.profile.src }else{this.soundObj[0].play() }}}}var sd=new FUI.soundComponent({src:'ding.wav',altSrc:'ding.mp3'})$('.fui-btn').bind('click',function(e){sd.play()}) </script>

/*这是页面的audio标签*//*这是js中的内容*//*设置背景音乐的音量为20%*//*volume的取值范围在0-1之间*/document.getElementById("bgAudio").volume=0.2

HTML5是构建Web内容的一种语言描述方式。HTML5是互联网的下一代标准,是构建以及呈现互联网内容的一种语言方式.被认为是互联网的核心技术之一。设置音量的方法为:

1、鼠标左键选中时间轴需要修改的音频。

2、用鼠标将音频导轨拖宽,直到看见一条中线为止。

3、Ctrl+鼠标左键,点击音频中线(也是音频音量的标准线),点击一下出现一个小点,这个点叫做关键点。

4、将中间的2、3点分别用鼠标左键向下拖拽。这样播放一下,效果——就声音变小,然后又恢复正常,如果想变大,就将第2、3关键点用鼠标左键向上托即可。如果2、3关键点都拖到低就会出现静音的效果。

注意事项:

与传统的技术相比,HTML5 的语法特征更加明显,并且结合了 SVG 的内容。这些内容在网页中使用可以更加便捷地处理多媒体内容,而且 HTML5中还结合了其他元素,对原有的功能进行调整和修改,进行标准化工作。