有关Js控件封装方法

 直接看代码,可以自己试试~!!

 这个控件主要是声音播放,成功or失败播放相应小型音频资源~!

/**
 @author Bill
 调用:
 container : 容器信息, 通过dom->id绑定 <input id="xxxx">
 showControls : 是否显示面板
 source : 资源路径
  
 注意配置好声音资源路径
 
 var video1 = new Ring({container:"test",showControls:true});
 video1.ring(1); // 1 OR 2
 

*/

window.Ring = function (param) {
    this.container = param.container;
    this._controls = param.showControls ? 'controls' : false; //是否显示播放器面板
    this._succSource = param.succSource ? param.succSource : "/Public/Common/ring/succ.wav";
    this._errSource = param.errSource ? param.errSource : "/Public/Common/ring/error.wav";
    this._ringPlay = null;
    this._video = null;
    this._init();
};
Ring.prototype = {
    constructor: Ring,
    _init: function () {
        var ring = this.createVideo();
        this.appendVideoToContainer(ring);
    },
    appendVideoToContainer:function (Ring) {
        if(!Ring){
            alert("铃声未成功初始化!");
            return false;
        }
        document.getElementById(this.container).appendChild(Ring);
    },
    createVideo:function(){
        var video = document.createElement("AUDIO");
        video.controls = this._controls;
        var _id = this.container + "_" + "video";
        video.setAttribute("id",_id);
        this._ringPlay = _id;
        this._video = video;
        return video;
    },
    ring:function(type){
        var _video = this.getVideoElement();
        if(type == 1){
            _video.src = this._succSource;
        }
        if(type == 2){
            _video.src = this._errSource;
        }
        var playVideo = document.getElementById(this._ringPlay);
        playVideo.play();
    },
    getVideoElement:function(){
        return this._video;
    }
};

注意仔细阅读!!!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值