html 自定义弹出选择框,jsjQuery实现自定义弹出框效果.html

弹出框

* {

padding: 0;

margin: 0;

}

.flex-container {

display: -webkit-flex;

display: flex;

-webkit-justify-content: space-between;

justify-content: space-between;

}

.window {

width: 20%;

padding-bottom: 20px;

background-color: #fff;

position: fixed;

display: none;

margin-bottom: 100px;

border: 1px solid #E0DFDF;

}

.add_btn {

height: 1400px;

cursor: pointer;

}

.btn_text {

width: 80px;

height: 40px;

line-height: 40px;

text-align: center;

color: #fff;

position: absolute;

top: 50%;

left: 50%;

margin-top: -40px;

margin-left: -20px;

background-color: #FDDB54;

}

.border_add_nav {

width: 100%;

border-bottom: 1px solid #E0DFDF;

}

.border_add_nav_box {

width: 90%;

margin: 0 auto;

font-size: 16px;

}

.border_add_main_content {

width: 100%;

margin-left: 5%;

margin-bottom: 3%;

overflow: hidden;

overflow-y: auto;

}

.border_add_btn_box {

width: 90%;

height: 100%;

margin: 0 auto;

overflow: hidden;

}

.add_title {

color: #20AAE4;

}

.name,

.input {

margin-top: 30px;

float: left;

}

.input {

width: 160px;

height: 40px;

text-align: center;

outline: none;

appearance: none;

-moz-appearance: none;

border-radius: 4px;

border: 1px solid #c8cccf;

color: #000;

}

.cancel,

.save {

width: 80px;

height: 40px;

line-height: 40px;

float: left;

color: #fff;

text-align: center;

border-radius: 5%;

cursor: pointer;

}

.cancel {

margin-right: 10px;

background: #E0DFDF;

}

.save {

background: #20AAE4;

}

.mask {

position: absolute;

top: 0;

display: none;

background-color: rgba(0, 0, 0, 0.5);

}

添加

新增

X

名称:

取消
保存

$(window).ready(function() {

$("#btn_center").click(function() {

$('.mask').css('display', 'block');

$('.mask').css('width', $(window).width())

$('.mask').css('height', $(document).height())

popCenterWindow();

});

});

//获取窗口的高度

var windowHeight;

//获取窗口的宽度

var windowWidth;

//获取弹窗的宽度

var popWidth;

//获取弹窗高度

var popHeight;

function init() {

windowHeight = $(window).height();

windowWidth = $(window).width();

popHeight = $(".window").height();

popWidth = $(".window").width();

}

//关闭窗口的方法

function closeWindow() {

$(".close_btn").click(function() {

$('.window').hide("slow");

$('.mask').css('display', 'none');

});

}

//定义弹出居中窗口的方法

function popCenterWindow() {

init();

//计算弹出窗口的左上角X的偏移量

var popX = (windowWidth - popWidth) / 2;

// 计算弹出窗口的左上角Y的偏移量为窗口的高度 - 弹窗高度 / 2 + 被卷去的页面的top

var popY = (windowHeight - popHeight) / 2 + $(document).scrollTop();

//设定窗口的位置

$("#center").css("top", popY).css("left", popX).slideToggle("fast");

closeWindow();

}

一键复制

编辑

Web IDE

原始数据

按行查看

历史

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
PHP和jQuery UI框都是常用的Web开发工具。下面简单介绍一下jQuery UI框插件`jquery.ui.dialog`的用法。 1. 引入jQuery和jQuery UI库文件 在HTML文件中引入jQuery和jQuery UI库文件: ``` <script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js"></script> <link rel="stylesheet" href="https://cdn.bootcss.com/jqueryui/1.12.1/jquery-ui.min.css"> <script src="https://cdn.bootcss.com/jqueryui/1.12.1/jquery-ui.min.js"></script> ``` 2. 创建一个框 在JavaScript代码中,使用`jquery.ui.dialog`方法创建一个框。 ``` $(function() { $("#dialog").dialog(); }); ``` 其中,`#dialog`是一个指向框DOM元素的CSS选择器。这个DOM元素可以是一个`<div>`标签。 3. 设置框选项 `jquery.ui.dialog`方法可以接收一个选项对象作为参数,用于设置框的一些属性。 ``` $(function() { $("#dialog").dialog({ autoOpen: false, modal: true, title: "框标题", width: 400, height: 300, buttons: { "确定": function() { $(this).dialog("close"); }, "取消": function() { $(this).dialog("close"); } } }); }); ``` 常用选项包括: - `autoOpen`:是否在页面加载完成后自动打开框,默认为`true`。 - `modal`:是否为模态框,默认为`false`。 - `title`:框标题。 - `width`和`height`:框宽度和高度。 - `buttons`:自定义按钮。 4. 打开和关闭框 使用`jquery.ui.dialog`方法中的`open`和`close`方法打开和关闭框。 ``` $(function() { $("#dialog").dialog({ autoOpen: false, modal: true, title: "框标题", width: 400, height: 300, buttons: { "确定": function() { $(this).dialog("close"); }, "取消": function() { $(this).dialog("close"); } } }); $("#openDialogBtn").click(function() { $("#dialog").dialog("open"); }); }); ``` 其中,`#openDialogBtn`是一个指向打开框按钮DOM元素的CSS选择器。 以上是`jquery.ui.dialog`的用法分析,希望能对你有所帮助。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值