html5触发式音频播放特效代码

版权:原创 更新时间:1年以上
[该文章底部包含文件资源,可根据自己情况,决定是否下载资源使用,时间>金钱,如有需要,立即查看资源]

以下是 html5触发式音频播放特效代码 的示例演示效果:

当前平台(PC电脑)
  • 平台:

部分效果截图:

html5触发式音频播放特效代码

HTML代码(index.html):

<!DOCTYPE html>
<html>

<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<title>html5触发式音频播放</title>
	<link rel='stylesheet' href='css/style.css'>
	<script src="js/jquery.min.js"></script>
</head>

<body>

	<div id="page-wrap">
	
		<header><div class="inside">
			<h1>Play Audio on :hover</h1>
			
			<p>We&#39;re going to use HTML5 here, no Flash. We&#39;ll need an audio 
			element with both MP3 (WebKit, IE) and OGG (Firefox, Opera). </p>
			
			<pre><code>&lt;audio controls preload=&quot;auto&quot;&gt;
	&lt;source src=&quot;audio/beep.mp3&quot; controls&gt;&lt;/source&gt;
	&lt;source src=&quot;audio/beep.ogg&quot; controls&gt;&lt;/source&gt;
	Your browser isn&#39;t invited for super fun audio time.
&lt;/audio&gt;</code></pre>

		<p>We&#39;re using jQuery in this demo to make selecting things and events 
		easier, but the .play() function is native. You probably wouldn&#39;t show 
		the audio element, that&#39;s for demo purposes only, <strong>just remove 
		the control attribute to not show anything.</strong></p>
		</div></header>
		
		<section id="one"><div class="inside">
		
		<h2>One &lt;audio&gt; for all menu items</h2>

		<p>.play() won&#39;t force the audio clip to start over unless it&#39;s finished 
		first, not very smooth.</p>
		
		<ul id="nav-one" class="nav">
		   <li>
		   	<a href="#">Home</a>
		   	<audio id="beep-one" controls="controls" preload="auto">
				<source src="audio/beep.mp3"></source>
				<source src="audio/beep.ogg"></source>
				Your browser isn&#39;t invited for super fun time.
			</audio>
			</li>
		   <li><a href="#">About</a></li>
		   <li><a href="#">Clients</a></li>
		   <li><a href="#">Contact Us</a></li>
		</ul>
		
		<script>var beepOne = $("#beep-one")[0];
$("#nav-one a")
	.mouseenter(function() {
		beepOne.play();
	});</script>
		
		</div></section>
		
		<section id="three"><div class="inside">
		
		<h2>One &lt;audio&gt; for all menu items, with pause</h2>

		<p>.pause() ing first should stop it and then play new sound but it 
		actually makes it worse somehow. Sounds get chopped off but not 
		restarted.</p>
		
		<ul id="nav-three" class="nav">
		   <li>
		   	<a href="#">Home</a>
			<audio id="beep-three" controls preload="auto">
				<source src="audio/beep.mp3" controls></source>
				<source src="audio/beep.ogg" controls></source>
				Your browser isn&#39;t invited for super fun time.
			</audio>
			</li>
		   <li><a href="#">About</a></li>
		   <li><a href="#">Clients</a></li>
		   <li><a href="#">Contact Us</a></li>
		</ul>
		
		<script>var beepThree = $("#beep-three")[0];
$("#nav-three a")
	.mouseenter(function() {
		beepThree.pause();
		beepThree.play();
	});</script>
		
		</div></section>
		
		<section id="two"><div class="inside">
		
		<h2>Cloned &lt;audio&gt;, one for each menu item</h2>
		
		<p>Smoothest but not perfect.</p>
				
		<ul id="nav-two" class="nav">
		   <li>
		   	<a href="#">Home</a>
		   	<audio id="beep-two" controls preload="auto">
				<source src="audio/beep.mp3" controls></source>
				<source src="audio/beep.ogg" controls></source>
				Your browser isn&#39;t invited for super fun time.
			</audio>
			</li>
		   <li><a href="#">About</a></li>
		   <li><a href="#">Clients</a></li>
		   <li><a href="#">Contact Us</a></li>
		</ul>
		
		<script>$("#nav-two a")
  .each(function(i) {
    if (i != 0) { 
      $("#beep-two")
        .clone()
        .attr("id", "beep-two" + i)
        .appendTo($(this).parent()); 
    }
    $(this).data("beeper", i);
  })
  .mouseenter(function() {
    $("#beep-two" + $(this).data("beeper"))[0].play();
  });
$("#beep-two").attr("id", "beep-two0");</script>
		
		</div></section>
	</div>
</body>
</html>







CSS代码(style.css):

/* CSS-Tricks Example by Chris Coyier http://css-tricks.com*/
*{margin:0;padding:0;}
body{font:14px/1.4 Georgia,serif;}
article,aside,figure,footer,header,hgroup,menu,nav,section{display:block;}
header{background:black;color:white;padding:80px 0 10px 0;}
h1,h2{font-weight:normal;}
h1{font-size:50px;margin:0 0 10px 0;}
h2{font-size:38px;margin:0 0 10px 0;}
p,pre{margin:0 0 15px 0;}
.inside{width:960px;margin:0 auto;}
section{padding:20px 0;overflow:hidden;}
#one{background:#6f4b7c;}
#two{background:#3c7ab5;}
#three{background:#ffeca9;}
.nav{width:120px;float:left;list-style:none;}
.nav li{position:relative;}
.nav a{display:block;padding:20px;text-decoration:none;color:white;background-image:-moz-linear-gradient(bottom,#444444,#999999);/* FF3.6 */
background-image:-o-linear-gradient(bottom,#444444,#999999);/* Opera 11.10+ */
background-image:-webkit-gradient(linear,left top,left bottom,from(#444444),to(#999999));/* Saf4+,Chrome */
background-image:-webkit-linear-gradient(bottom,#444444,#999999);/* Chrome 10+,Saf5.1+ */
}
.nav a:hover{background:#222;}
.nav audio{position:absolute;left:110%;top:10px;display:block;height:30px;width:200px;}
#page-wrap script{display:block;white-space:pre;background:#333;color:white;padding:10px;font:11px Monaco,MonoSpace;width:460px;float:right;overflow:auto;}
附件:下载该文件资源,减少时间成本(增值服务)
留言
该资源可下载
File Source
.rar
46.45 KB
Html Js 播放器
最新结算
jquery虚拟键盘中文打字效果js代码
类型: .rar 金额: CNY 2.31¥ 状态: 待结算 详细>
jquery虚拟键盘中文打字效果js代码
类型: .rar 金额: CNY 0.29¥ 状态: 待结算 详细>
HTML5实现CSS滤镜图片切换特效代码
类型: .rar 金额: CNY 2.31¥ 状态: 待结算 详细>
jQuery头像裁剪插件cropbox js代码
类型: .rar 金额: CNY 0.29¥ 状态: 待结算 详细>
jQuery头像裁剪插件cropbox js代码
类型: .rar 金额: CNY 2.31¥ 状态: 待结算 详细>
CSS3制作3D图片立方体旋转特效
类型: .rar 金额: CNY 2.31¥ 状态: 待结算 详细>
CSS3制作3D图片立方体旋转特效
类型: .rar 金额: CNY 0.29¥ 状态: 待结算 详细>
CSS3制作3D图片立方体旋转特效
类型: .rar 金额: CNY 2.31¥ 状态: 待结算 详细>
CSS3制作3D图片立方体旋转特效
类型: .rar 金额: CNY 0.29¥ 状态: 待结算 详细>
jQuery+css3实现信封效果
类型: .rar 金额: CNY 0.29¥ 状态: 待结算 详细>
我们力求给您提供有用的文章,再此基础上,会附加营收资源,不做任何广告,让平台可以更好发展 若您发现您的权利被侵害,或使用了您的版权,请发邮件联系 sunlifel@foxmail.com ggbig觉得 : 不提供源码的文章不是好文章
合作伙伴
联系我们
  • QQ:21499807
  • 邮箱:sunlifel@foxmail.com
  • QQ扫一扫加QQ
    QQ扫一扫
Copyright 2023-2024 ggbig.com·皖ICP备2023004211号-1
打赏文章