layer

(function(w){

    function Layer(){

        this.init();

    }
    Layer.prototype.init=function(){

        if(document.getElementById(‘layer_oby‘)){//如果已经存在的情况

            this.oLayer=document.getElementById(‘layer_oby‘);

        }else{
            this.oLayer=document.createElement(‘div‘);
            this.oLayer.id=‘layer_oby‘;
        }
        Layer.prototype.init.prototype=Layer.prototype;
        return new init();

    }
    Layer.prototype.msg=function(msg,time){//消息提示
        var self=this;
        var time=time===undefined?2000:time;//默认两秒钟后消失
        this.oLayer.innerHTML=msg;

        //添加内容后才设置样式

        document.body.appendChild(this.oLayer);
        this.oLayer.style.display=‘none‘;
        this.oLayer.style.opacity=‘0‘;
        this.setCss();

        Layer.tool.opacityMove(0,1,this.oLayer,function(){

            setTimeout(function(){
                Layer.tool.opacityMove(1,0,self.oLayer,function(){
                    self.oLayer.style.display=‘none‘;
                    self.oLayer.parentNode.removeChild(self.oLayer);
                });
            },time);
        });

    }
    Layer.prototype.alert=function(msg){
        var self=this;

        this.oLayer.innerHTML=msg;
        //添加内容后才设置样式

        document.body.appendChild(this.oLayer);

        this.setCss();

        this.setClose();

        this.oLayer.addEventListener(‘click‘,function(ev){

            if(ev.target.id==‘close_oby‘){

                self.oLayer.style.display=‘none‘;

            }
        });
    }
    Layer.prototype.setClose=function(){//设置关闭按钮

        this.closeBtn=document.createElement(‘span‘);
        this.closeBtn.innerHTML=‘ב;
        this.closeBtn.id=‘close_oby‘;
        this.oLayer.appendChild(this.closeBtn);

        //设置样式
        this.closeBtn.style.position=‘absolute‘;
        this.closeBtn.style.top=‘10px‘;
        this.closeBtn.style.right=‘10px‘;
        this.closeBtn.style.fontSize=‘22px‘;
        this.closeBtn.style.fontWeight=‘bold‘;
        this.closeBtn.style.cursor=‘pointer‘;

    }
    Layer.prototype.setCss=function(){//设置样式

        var currentWidth,currentHeight;

        this.oLayer.style.maxWidth=‘300px‘;
        this.oLayer.style.padding=‘20px 30px‘;
        this.oLayer.style.background=‘rgba(0,0,0,0.8)‘;
        this.oLayer.style.position=‘absolute‘;
        this.oLayer.style.color=‘#fff‘;
        this.oLayer.style.wordBreak=‘break-word‘;
        currentWidth=parseInt(Layer.tool.getStyle(this.oLayer,‘width‘));
        currentHeight=parseInt(Layer.tool.getStyle(this.oLayer,‘height‘));

        this.oLayer.style.marginLeft=-currentWidth/2+‘px‘;
        this.oLayer.style.marginTop=-currentHeight/2+‘px‘;
        this.oLayer.style.top=‘50%‘;
        this.oLayer.style.left=‘50%‘;

    }

    Layer.tool={
        getStyle:function(obj,attr){//获取当前样式
            return window.getComputedStyle(obj, null)[attr];
        },
        opacityMove:function(start,end,obj,callback){//透明度变化
            var start=start;
            var end=end;
            var step=start<end?0.2:-0.2;
            var timer=null;

            timer=setInterval(function(){
                start+=step;
                if((step>0&&start>end)||(step<0&&start<end)){
                    clearInterval(timer);
                    callback?callback():‘‘;
                }else{
                    obj.style.opacity=start;

                }

            },100)
        }
    }
    w.layer=Layer;

})(window);
时间: 2024-08-06 03:44:37

layer的相关文章

自定义Layer的两种方法

view的完整显示过程: 1.view.layer会准备一个Layer Graphics Context(图层类型上下文) 2.调用view.layer.delegate(即view)的drawLayer:inContext:并传入准备好的上下文 3.view的drawLayer:inContext:方法内部会调用view的drawRect:方法 4.view就可以在drawRect:方法中实现绘图,所有东西都会绘制到view.layer上 5.系统再将view.layer内容拷贝到屏幕上,完成

Orchard 之:Widget,兼看 Layer 在权限控制中的作用

一:Widget 可以理解为控件,可以直接被页面所引用.行为类似与分部页面,比如,我们可以创建一个 商品列表 Widget,然后这个 Widget 就可以被很多页面所引用. 理解 Widget 这个概念,我们不得不理解另外两个概念: 1:Layer Orchard 默认有这么几个层,Default.Authenticated.Anonymous.Disabled.TheHomepage.Layer 用于承载什么时候 Widget 将会被展现,这么讲大家一定觉得很抽象,其实 Layer 存在的意义

layer.js子窗口关闭并传数据到父窗的方法

昨晚整了很晚,一直找不到方法.去官网api看了好久,又在网上搜了很久 始终找不到答案.今天自己终于找到了方法. 难点:因为 确认和取消按钮都是在父窗 调用js生成的按钮.只能从父窗回调的时候去去数据并关闭子窗口.并不是子窗口自己关闭并把数据传到父窗.而网上给出的很多答案都是子窗口自己关闭并传数据到父窗的方法. [贴出我自己的代码,大概实现了流程.具体自己根据情况修改] 我的代码功能是 子窗口要传递数组给父窗,具体复杂的数据格式(如json等)类似 1.子窗口代码 var urls; functi

layer实现在前台删除前确认弹出框,并回调后台删除事件

最近遇到一些问题,用layer提示消息框,比如删除时,提示消息确定后 return false时,则不管用了,因为layer不支持阻塞,下面就解决一下这个问题: 删除按钮代码: <asp:Button ID="btnDel" name="btnDel" runat="server" Text="删除" class="btn btn-gray" OnClientClick="return re

【Caffe代码解析】Layer网络层

Layer 功能: 是全部的网络层的基类,当中.定义了一些通用的接口,比方前馈.反馈.reshape,setup等. #ifndef CAFFE_LAYER_H_ #define CAFFE_LAYER_H_ #include <algorithm> #include <string> #include <vector> #include "caffe/blob.hpp" #include "caffe/common.hpp" #

layer弹框的上面各个属性 -可配置

<script type="text/javascript"> 12 //eg 13 layer.open({ 14 title:"标题信息提示",//标题信息 15 content: 'test',//内容区域 16 move: false,//是否可以拖动,默认可以拖动 17 btn: ['按钮一', '按钮二', '按钮三'], 18 btn1: function(index){ 19 //按钮[按钮一]的回调 20 layer.close(ind

U3D sorting layer, sort order, order in layer, layer深入辨析

1,layer是对游戏中所有物体的分类别划分,如UIlayer, waterlayer, 3DModelLayer, smallAssetsLayer, effectLayer等.将不同类的物体划分到不同的层,便于相机拣选,在相机的cullmask中可以选择渲染哪些层,不选择的层则不会渲染.还可以用于射线检测对象的拣选,可以指定只对某些层的对象进行射线检测. 2,canvas默认是屏幕空间的2D对象,在屏幕空间时仅具有sort order属性,当把它设置为世界空间时,sort order属性消失

self.view.layer.contents 和 self.view.backgroundColor

一. self.view.layer.contents 和 self.view.backgroundColor 今天测了一下 :    self.view.layer.contents 和 self.view.backgroundColor 例子: self.view.layer.contents = (id)[UIImage imageNamed:@"musicBackground.jpg"].CGImage; self.view.backgroundColor = [UIColor

Tips3:通过Layer下拉菜单来锁定游戏物体和控制物体的可视化

通过把不同的游戏物体放在不同的Layer里面能对不同类的游戏物体进行很方便的控制,如果某些游戏物体创建后你不想再改动,如地面 装饰 什么的, 你可以通过点击Layer下拉菜单把它们锁定了 也可以通过控制Layer下拉菜单中的眼睛图标来设置是否 显示 或 隐藏 layer里的物体 这里需要注意的是,Unity中 Layer 最多有25个,不过对我们来说已经非常够用了.