zoukankan      html  css  js  c++  java
  • html5 音乐 audio

    手机做小项目,需要添加音乐,做此笔记,依赖jquery,代码如下:

    <!DOCTYPE html>
    <html lang="en">
    <head>
    	<meta charset="UTF-8">
    	<title>Document</title>
    	<style>
    	*{ margin:0; padding:0; }
    /**
     * 声音元件
     */
    .z-hide{ display:none; }
    .u-audio { position: absolute; top: 40px; right:20px;  132px; height: 73px; z-index: 200; }
    .u-audio .btn_audio {  100%; padding-top: 29px; height: 44px; border:1px solid #eee; }
    .u-audio .btn_audio .audio_open { display: inline-block; height: 44px; line-height: 44px; vertical-align: middle; background-color:#eee; cursor:pointer; position: absolute; bottom: 0; left: 56px;  44px; }
    .u-audio.z-low { z-index: 1; }
    </style>
    </head>
    <body>
    	<!-- 音乐 -->
        <section class='u-audio f-hide' data-src='onlylove.mp3'>
          <p class="btn_audio">
          <strong class='txt_audio z-hide'>关闭</strong>
          <span class='css_sprite01 audio_open'></span>
          </p>
        </section>
    
    	<script src="js/jquery-1.8.2.min.js"></script>
    	<script>
    	;(function($){
    		function vedioFun(){
    			this._audioNode = $(".u-audio");
    			this._audio = null;
    		}
    		vedioFun.prototype.audio_init = function(){
    			if (this._audioNode.length >0 ){
    				var t = {
    					loop: !0,
    					preload: "auto",
    					src: this._audioNode.attr("data-src")
    				};
    				this._audio = new Audio;
    				for (var e in t) t.hasOwnProperty(e) && e in this._audio && (this._audio[e] = t[e]);
    				this._audio.load();
    			}
    		}
    		vedioFun.prototype.audio_addEvent = function() {
    			var audio = this._audioNode.find(".txt_audio"),
    				a = null,
    				btn = audio.siblings(".audio_open");
    			function t(t, e, n) {
    				if(e){
    					t.text("打开");
    					btn.addClass("js-audio-open");
    				}else{
    					t.text("关闭");
    					btn.removeClass("js-audio-open");
    				}
    				n && clearTimeout(n),
    				t.removeClass("z-move z-hide"),
    				n = setTimeout(function() {
    					t.addClass("z-move").addClass("z-hide")
    				},1e3);
    			}
    			if (this._audioNode.length > 0) {
    				$(this._audio).on("play",function(){
    					t(audio, !0, a);
    				}),
    				$(this._audio).on("pause",function(){
    					t(audio, !1, a);
    				})
    			}
    		}
    		vedioFun.prototype.media_init = function(){
    			var self = this;
    			self.audio_init();
    			self.audio_addEvent();
    			$(window).on("load",function() {
    				self._audio.play();
    				self._audioNode.find(".btn_audio").on("click",function() {
    					self._audio.paused ? self._audio.play() : self._audio.pause()
    				});
    			});
    		}
    		var video = new vedioFun();
    		video.media_init();
    	})(jQuery);
    	</script>
    </body>
    </html>
    

      

  • 相关阅读:
    laravel框架简易对接网易163邮件
    新版PHP7安装redis扩展并在laravel中运用
    make: as86: Command not found
    Ubuntu主题美化
    Ubuntu更换阿里源
    Ubuntu配置中文输入法
    JS内利用Ajax同后端异步交互数据
    更改网页内滚动条效果
    鼠标点击烟花特效
    内存交换分区创建&文件系统观察与操作
  • 原文地址:https://www.cnblogs.com/cyj7/p/4633625.html
Copyright © 2011-2022 走看看