js实现弹窗插件功能实例代码分享-javascript编程(二)

您好,欢迎来到百闽人生网登录 注册

百闽首页 | 考试日历 | 百闽娱乐 | 书信频道 | 节日庆典 | 语录句子 | 免费发布培训课程

百闽人生网

百闽人生网 > 培训新闻 > 电脑/IT > js实现弹窗插件功能实例代码分享-javascript编程(二)

js实现弹窗插件功能实例代码分享-javascript编程(二)

  JS代码如下

    复制代码 代码如下:

    /**

    * 编写JS弹窗组件

    * @date 2013-12-10

    * @author tugenhua

    * @email 879083421@qq.com

    */

    function Overlay(options){

    this.config = {

    targetCls : ".clickElem", // 点击元素

    title: "我是龙恩", // 窗口标题

    content : "text:

我是龙恩

",

    //content : "img:http://gtms01.alicdn.com/tps/i1/T1USkqFc0dXXb5rXb6-1060-300.jpg",

    // 窗口内容 {text:具体内容 | id:id名 | img:图片链接 |

    // iframe:src链接} {string}

    width: 400, // 内容的宽度

    height : 300, // 内容的高度

    theight : 30,// 标题的高度 默认为30

    drag : true, // 是否可以拖动 默认为true

    time : 3000, // 自动关闭窗口的时间 为空或者"undefined"则不关闭

    showBg : true, // 设置是否显示遮罩层 默认为true 遮罩

    closable : "#window-close", // 关闭按钮

    bgColor : "#000", // 默认颜色

    opacity : 0.5,// 默认透明度

    position : {

    x: 0,

    y: 0 //默认等于0 居中

    },

    zIndex : 10000,

    isScroll : true, //默认情况下 窗口随着滚动而滚动

    isResize : true, // 默认情况下 随着窗口缩放而缩放

    callback : null//弹窗显示后回调函数

    };

    this.cache = {

    isrender : true, // 弹窗html结构只渲染一次

    isshow: false, // 窗口是否已经显示出来

    moveable : false

    };

    this.init(options);

    }

    Overlay.prototype = {

    constructor: Overlay,

    init: function(options){

    this.config = $.extend(this.config,options || {});

    var self = this,

    _config = self.config,

    _cache = self.cache;

    $(_config.targetCls).each(function(index,item){

    $(item).unbind("click");

    $(item).bind("click",function(){

    // 渲染弹窗HTML结构

    self._renderHTML();

    // 窗口移动

    self._windowMove();

    });

    });

    // 窗口缩放

    self._windowResize("#window-box");

    // 窗口随着滚动条一起滚动

    self._windowIsScroll("#window-box");

    },

    /*

    * 渲染弹窗HTML结构

    */

    _renderHTML: function(){

    var self = this,

    _config = self.config,

    _cache = self.cache;

    var html ="";

    if(_cache.isrender) {

    html+= "

" +

    "

";

    $("body").append(html);

    $("#windowbg").css("z-index",_config.zIndex);

    $("#window-content-border").css({"width":_config.width + "px","height":_config.height + "px","overflow":"auto"});

    $(".window-title h2").html(_config.title);

    $(".window-title").css({"height":_config.theight + "px","width":_config.width,"overflow":"hidden

首页 1 2 3 4 下页 

关于我们 | 招生合作 | 负责声明 | 常见问题 | 诚聘英才 | 联系我们

Copyright©2014 www.bminlife.com 百闽人生网 版权所有©百闽人生网 闽ICP备14001301号
本文标题:js实现弹窗插件功能实例代码分享-javascript编程
分站加盟及广告服务QQ:1476191318
友情提示:本站所有信息均由本站注册会员免费发布,如涉及版权问题或虚假信息请及时与本站联系。——我们一直在追求真实!