AJAX里使用的弹窗样式 tanchuang.js tanchuang.css

tanchuang.js

// 每个弹窗的标识
var x =0;
var idzt = new Array();

var Window = function(config){

    //ID不重复
    idzt[x] = "zhuti"+x;  //弹窗ID

    //初始化,接收参数
    this.config = {
        width : config.width || 300, //宽度
        height : config.height || 200, //高度
        buttons : config.buttons || ‘‘, //默认无按钮
        title : config.title || ‘标题‘, //标题
        content : config.content || ‘内容‘, //内容
        isMask : config.isMask == false?false:config.isMask || true, //是否遮罩
        isDrag : config.isDrag == false?false:config.isDrag || true, //是否移动
        };

    //加载弹出窗口
    var w = ($(window).width()-this.config.width)/2;
    var h = ($(window).height()-this.config.height)/2;

    var nr = "<div class=‘zhuti‘ id=‘"+idzt[x]+"‘ bs=‘"+x+"‘ style=‘width:"+this.config.width+"px; height:"+this.config.height+"px; background-color:white; left:"+w+"px; top:"+h+"px;‘></div>";
    $("body").append(nr);

    //加载弹窗标题
    var content ="<div id=‘title"+x+"‘ class=‘title‘ bs=‘"+x+"‘>"+this.config.title+"<div id=‘close"+x+"‘ class=‘close‘ bs=‘"+x+"‘>×</div></div>";
    //加载弹窗内容
    var nrh = this.config.height - 75;
    content = content+"<div id=‘content"+x+"‘ bs=‘"+x+"‘ class=‘content‘ style=‘width:100%; height:"+nrh+"px;‘>"+this.config.content+"</div>";
    //加载按钮
    content = content+"<div id=‘btnx"+x+"‘ bs=‘"+x+"‘ class=‘btnx‘>"+this.config.buttons+"</div>";

    //将标题、内容及按钮添加进窗口
    $(‘#‘+idzt[x]).html(content);

    //创建遮罩层
    if(this.config.isMask)
    {
        var zz = "<div id=‘zz‘></div>";
        $("body").append(zz);
        $("#zz").css(‘display‘,‘block‘);
    }

    //最大最小限制,以免移动到页面外
    var maxX = $(window).width()-this.config.width;
    var maxY = $(window).height()-this.config.height;
    var minX = 0,
        minY = 0;

    //窗口移动
    if(this.config.isDrag)
    {
        //鼠标移动弹出窗
        $(".title").bind("mousedown",function(e){

                var n = this.getAttribute("bs"); //取标识

                //使选中的到最上层
                $(".zhuti").css("z-index",3);
                $(‘#‘+idzt[n]).css("z-index",4);

                //取初始坐标
                var endX = 0, //移动后X坐标
                    endY = 0, //移动后Y坐标
                    startX = parseInt($(‘#‘+idzt[n]).css("left")), //弹出层的初始X坐标
                    startY = parseInt($(‘#‘+idzt[n]).css("top")), //弹出层的初始Y坐标
                    downX = e.clientX, //鼠标按下时,鼠标的X坐标
                    downY = e.clientY; //鼠标按下时,鼠标的Y坐标

                //绑定鼠标移动事件
                $("body").bind("mousemove",function(es){

                    endX = es.clientX - downX + startX; //X坐标移动
                    endY = es.clientY - downY + startY; //Y坐标移动

                    //最大最小限制
                    if(endX > maxX)
                    {
                        endX = maxX;
                    } else if(endX < 0)
                    {
                        endX = 0;
                    }
                    if(endY > maxY)
                    {
                        endY = maxY;
                    } else if(endY < 0)
                    {
                        endY = 0;
                    }

                    $(‘#‘+idzt[n]).css("top",endY+"px");
                    $(‘#‘+idzt[n]).css("left",endX+"px");

                    window.getSelection ? window.getSelection().removeAllRanges():document.selection.empty(); //取消选中文本

                    });
            });
        //鼠标按键抬起,释放移动事件
        $("body").bind("mouseup",function(){

                $("body").unbind("mousemove");

            });
    }

    //关闭窗口
    $(".close").click(function(){

            var m = this.getAttribute("bs"); //找标识
            $(‘#‘+idzt[m]).remove(); //移除弹窗
            $(‘#zz‘).remove(); //移除遮罩 

        })

        x++;  //标识增加

}

tanchuang.css

.zhuti
{
    position:absolute;
    z-index:3;
    font-size:14px;
    border-radius:5px;
    box-shadow:0 0 5px white;
    overflow:hidden;
    color:#333;
}
.title
{
    background-color:#3498db;
    vertical-align:middle;
    height:35px;
    width:100%;
    line-height:35px;
    text-indent:1em;
}
.close{
    float:right;
    width:35px;
    height:35px;
    font-weight:bold;
    line-height:35px;
    vertical-align:middle;
    color:white;
    font-size:18px;
    }
.close:hover
{
    cursor:pointer;
}
.content
{
    text-indent:1em;
    padding-top:10px;
}
.btnx
{
    height:30px;
    width:100%;
    text-indent:1em;
}
.btn
{
    height:28px;
    width:80px;
    float:left;
    margin-left:20px;
    color:#333;
}
#zz
{
    width:100%;
    height:100%;
    opacity:0.15;
    display:none;
    background-color:#ccc;
    z-index:2;
    position:absolute;
    top:0px;
    left:0px;
}
时间: 2024-08-10 02:10:50

AJAX里使用的弹窗样式 tanchuang.js tanchuang.css的相关文章

ajax做显示信息以后用ajax、Bootstrp做弹窗显示信息详情

nation.php 1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 2 <html xmlns="http://www.w3.org/1999/xhtml"> 3 <head> 4 <meta http-e

11月10日下午 ajax做显示信息以后用ajax、Bootstrp做弹窗显示信息详情

1.用ajax做弹窗显示信息详情 nation.php <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <me

JS 控制CSS样式表

JS控制CSS样式,首先得确定一点,CSS与HTML页面的链接方式,因为CSS有3种与HTML页面结合的方式,不同的方式也会产生不同的结果. 下面先记录一下JS控制CSS所使用的方法. 1.使用javascript更改某个css class的属性... 1 <style type="text/css"> 2 .orig { 3 display: none; 4 } 5 </style> 你想要改变把他的display属性由none改为inline. 解决办法:

ajax 里的数据请求

今天给大家讲讲前端怎样通过ajax里的 get 和post两种方法来发送数据请求 首先,我们先知道 ajax里的get  post里有两个属性, open(),send().还要区分同步请求还是异步请求 在我们以后参加工作的时候用的比较多的都是异步请求 true: 那我们先来说说异步的请求方法 当然这里也不能漏了同步请求 上面的 是通过get的方法来请求的 date.json是我需要请求的数据地址 这里大家知道怎么请求的方法就可以了 一般你在参加工作之后会有后端的数据库人员会给你相应的数据库地址

在AJAX里 使用【 XML 】 返回数据类型 实现简单的下拉菜单数据

在AJAX里 使用XML返回数据类型 实现简单的下拉菜单数据 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <

在AJAX里 使用【 JSON 】 返回数据类型 实现简单的下拉菜单数据

在AJAX里 使用JSON返回数据类型 实现简单的下拉菜单数据 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> &l

将Microsoft Ajax Minifier集成到VS2013对JS、CSS进行编译时压缩

在网站发布中,一般要将js,css文件压缩减少体积,以减少在HTTP请求中的流量.将Microsoft Ajax Minifier集成到VS2013中就可以对JS.CSS进行编译时压缩. VS2013的集成方法: Asp.net网站上的详细说明网址:http://www.asp.net/ajaxlibrary/AjaxMinQuickStart.ashx      Microsoft Ajax Minifier下载地址:http://ajaxmin.codeplex.com/ 下载安装后,按照如

js 获取css 样式

style只能获取元素的行间样式. 原生代码获取css里的样式,currentStyle只适用于IE,getComputedStyle适用于FF.opera.safari.chrome. function getStyle ( obj, attr ) { return obj.currentStyle?obj.currentStyle[attr] : getComputedStyle( obj )[attr]; } js 获取css 样式

微信小程序自定义弹窗wcPop插件|仿微信弹窗样式

微信小程序自定义组件弹窗wcPop|小程序消息提示框|toast自定义模板弹窗 平时在开发小程序的时候,弹窗应用场景还是蛮广泛的,但是微信官方提供的弹窗比较有局限性,不能自定义修改.这个时候首先想到的是自定义组件化开发,就是把弹出框封装成一个组件,然后多处调用. 解决了小程序开发自定义弹窗出现后,遮罩层下的页面仍可以滚动的方法: 给遮罩层的最外层view中加入catchtouchmove="preventTouchMove" 即可解决该遮罩层点透问题. 根据需要还可以自定义多个按钮及事