html右侧划出层,点击按钮网页居中滑出覆盖层和消息提示盒子

本文介绍一个很常见的点击按钮后,网页居中滑出覆盖层和消息提示盒子的实例。

593c8186a39a011b8ec5f2d2bfbf8162.png

点击按钮网页居中滑出覆盖层和消息提示盒子

完整HTML代码html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

CSS和jQuery实现:网页居中滑出覆盖层

body{

font-family:Arial;

height:2000px;

}

.header

{

width:600px;

height:56px;

position:absolute;

top:0px;

left:25%;

background:#fff url(title.png) no-repeat top left;

}

a.back{

width:256px;

height:73px;

position:fixed;

bottom:15px;

right:15px;

background:#fff url(codrops_back.png) no-repeat top left;

z-index:1;

cursor:pointer;

}

a.activator{

width:153px;

height:150px;

position:absolute;

top:0px;

left:0px;

background:#fff url(clickme.png) no-repeat top left;

z-index:1;

cursor:pointer;

}

/* 覆盖层和消息盒子样式 */

.overlay{

background:transparent url(images/overlay.png) repeat top left;

position:fixed;

top:0px;

bottom:0px;

left:0px;

right:0px;

z-index:100;

}

.box{

position:fixed;

top:-200px;

left:30%;

right:30%;

background-color:#fff;

color:#7F7F7F;

padding:20px;

border:2px solid #ccc;

-moz-border-radius: 20px;

-webkit-border-radius:20px;

-khtml-border-radius:20px;

-moz-box-shadow: 0 1px 5px #333;

-webkit-box-shadow: 0 1px 5px #333;

z-index:101;

}

.box h1{

border-bottom: 1px dashed #7F7F7F;

margin:-20px -20px 0px -20px;

padding:10px;

background-color:#FFEFEF;

color:#EF7777;

-moz-border-radius:20px 20px 0px 0px;

-webkit-border-top-left-radius: 20px;

-webkit-border-top-right-radius: 20px;

-khtml-border-top-left-radius: 20px;

-khtml-border-top-right-radius: 20px;

}

a.boxclose{

float:right;

width:26px;

height:26px;

background:transparent url(images/cancel.png) repeat top left;

margin-top:-30px;

margin-right:-30px;

cursor:pointer;

}

重要信息

这是一个覆盖层。
单击交叉图标关闭此窗口。

$(function() {

$('#activator').click(function(){

$('#overlay').fadeIn('fast',function(){

$('#box').animate({'top':'160px'},500);

});

});

$('#boxclose').click(function(){

$('#box').animate({'top':'-200px'},500,function(){

$('#overlay').fadeOut('fast');

});

});

});

解释:

1、点击按钮

点击按钮的id是activator:

jquery对应的点击事件写法:$('#activator').click(function(){

$('#overlay').fadeIn('fast',function(){

$('#box').animate({'top':'160px'},500);

});

});

2、关闭按钮

关闭按钮的id是boxclose:

jquery对应的点击事件写法:$('#boxclose').click(function(){

$('#box').animate({'top':'-200px'},500,function(){

$('#overlay').fadeOut('fast');

});

});

3、消息盒子

消息盒子的html:

重要信息

这是一个覆盖层。
单击交叉图标关闭此窗口。

您可能对以下文章也感兴趣

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要在 Element UI 的 message 消息提示中添加按钮和点击事件,可以使用 Element UI 提供的 $message 方法,同时传入一个配置对象来实现。 以下是一个示例代码,创建一个带有按钮和点击事件的消息提示: ``` this.$message({ message: '这是一条带有按钮和点击事件的消息', duration: 0, showClose: true, center: true, customClass: 'message-box', type: 'warning', offset: 100, dangerouslyUseHTMLString: true, iconClass: 'el-icon-warning', customClass: 'message-box', showCancelButton: true, cancelButtonText: '取消', confirmButtonText: '确定', callback: action => { if (action === 'confirm') { // 点击确定按钮 console.log('点击了确定按钮') } else if (action === 'cancel') { // 点击取消按钮 console.log('点击了取消按钮') } } }) ``` 在这个示例中,我们使用了 Element UI 的 $message 方法来创建一个消息提示,同时传入一个配置对象。其中,我们设置了以下几个配置项: - `message`:消息提示的内容。 - `duration`:消息提示的持续时间。这里设置为 0,表示该消息提示不会自动关闭,需要点击按钮才能关闭。 - `showClose`:是否显示关闭按钮。这里设置为 true,表示该消息提示会显示一个关闭按钮。 - `center`:是否居中显示。这里设置为 true,表示该消息提示会在屏幕中央显示。 - `customClass`:自定义样式类名。这里设置为 message-box,表示该消息提示会应用一个名为 message-box 的样式。 - `type`:消息提示的类型。这里设置为 warning,表示该消息提示是一个警告类型。 - `offset`:消息提示的偏移量。这里设置为 100,表示该消息提示会在垂直方向上向下偏移 100 像素。 - `dangerouslyUseHTMLString`:是否将 message 字段作为 HTML 片段处理。这里设置为 true,表示 message 字段可以包含 HTML 标签。 - `iconClass`:自定义图标类名。这里设置为 el-icon-warning,表示该消息提示会使用一个名为 el-icon-warning 的图标。 - `showCancelButton`:是否显示取消按钮。这里设置为 true,表示该消息提示会显示一个取消按钮。 - `cancelButtonText`:取消按钮的文本。这里设置为 取消。 - `confirmButtonText`:确定按钮的文本。这里设置为 确定。 - `callback`:按钮点击后的回调函数。该函数会接收一个参数 action,表示用户点击的按钮。如果 action 等于 confirm,表示用户点击了确定按钮;如果 action 等于 cancel,表示用户点击了取消按钮。 在回调函数中,我们可以根据用户点击的按钮执行相应的操作。在这个示例中,我们只是简单地在控制台输出了一条消息。你可以根据自己的需求来编写具体的逻辑。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值