javascript右下角弹层及自动隐藏(自己编写)_jquery

在编写项目中总会需要有个右下角弹层提示公告的需求,怎么用更简单方面,更简洁代码,实现更好用户体验这个就是我们的所要做的内容。市场这块弹层很多,但功能不尽如人意。下面分享早些时候自己编写,以及现在还在应用的自动弹层。

弹层示例图:
 
实现代码如下:

Css样式:

复制代码 代码如下:

/*通知提示层*/
.msg_info{ font-size: 12px; text-align: left; z-index: 100; position: absolute; display: none; bottom: 0; right: 0; overflow: hidden;}
.msg_info h3{float: left;margin: 0px;height: 0px;width: 100%; color: #fff; height: 30px;}
.msg_info h3 span, .msg_info h3 b, .msg_info h3 em, .msg_info small span, .msg_info small b, .msg_info small em{ background-image: url(/img/msg_bg.png);}
.msg_info h3 b, .msg_info h3 em, .msg_info small b, .msg_info small em{ float: left;font-size: 1px; width: 6px; height: 30px;}
.msg_info h3 b{ background-position: 0px 0px;}
.msg_info h3 em{ background-position: 0px -32px;}
.msg_info h3 span{background-position: 0px -64px;float: left;line-height: 30px;}
.msg_info h3 span font{float: left;text-align: left;overflow: hidden; margin-left: 12px;}
.msg_info h3 span i{ float: right; margin-right: 10px; cursor: pointer;font-style:normal;}
.message_content{ float: left;color: #515F62;overflow: hidden;border-left: solid 1px #C2C2C2; background-color: #F1F2F7; margin-top: -1px; min-height: 145px; height: auto !important; height: 145px;}
.message_content div{ float: left; margin: 0px; padding: 10px 14px;height: 100%;position:relative;}
.message_content div p.message_txt{ float: left;width: 100%;height: 80%;margin: 0px; padding: 0px;min-height:60px;}
.message_content div i{float: left; font-style: normal; margin-top: 2px;text-align:right;position:fixed;bottom:2px;right:4px;}
.message_content b.bright{ float: right; width: 1px; font-size: 1px;background-color: #C2C2C2; border-right: solid 1px #828282;height: 100%;}
.msg_info small{float: left; width: 100%; height: 5px; font-size: 5px;}
.msg_info small span{ background-position: 0px -101px;height: 5px; float: left;}
.msg_info small b{height: 5px; background-position: 0px -96px;}
.msg_info small em{ height: 5px; background-position: 0px -106px; float: right;}

Js部分:

自定义右下角弹层函数

复制代码 代码如下:

//右下角弹层
function Messager() {
this.layer = { 'width': 200, 'height': 100 };
this.title = '信息提示';
this.time = 4000;
this.anims = { 'type': 'slide', 'speed': 600 };
this.timer1 = null;
this.isTiming = false;
this.obj_id = "msg_" + $(document.body).find('msg_info').length;

var _obj, _title, _anims, _time;
_timer2 = null;
//初始化
this.inits = function (title, text) {
_anims = this.anims;
_title = title;
var _html = '<div class="msg_info ' + this.obj_id + '">';
_html += ' <h3>';
_html += ' <b></b>';
_html += ' <span class="msg_bg_middle">';
_html += ' <font>' + title + '</font>';
_html += ' <i class="message_close">×</i>';
_html += ' </span>';
_html += ' <em></em>';
_html += ' </h3>';
_html += ' <div class="message_content">';
_html += ' <div class="msg_txt">' + text + '</div>';
_html += ' <b class="bright"></b>';
_html += ' </div>';
_html += ' <small><b></b><span class="msg_bg_middle"></span><em></em></small>';
_html += '</div>';
$(document.body).prepend(_html);

_obj = $("." + this.obj_id);
if ($.browser.msie) {
_obj.css('bottom', -5);
}
_obj.css('width', this.layer.width);
_obj.find('.msg_bg_middle').css('width', this.layer.width - 12);
_obj.find('.message_content').css('width', this.layer.width - 2);
_obj.find('.msg_txt').css('width', this.layer.width - 34);
_obj.find(".message_close").click(function () {
setTimeout(function () { closeMsg(); }, 1);
});
_obj.hover(function () {
clearTimeout(timer1);
clearInterval(_timer2);
_timer2 = timer1 = null;
}, function () {
timer1 = setTimeout(function () { closeMsg(); }, _time * 1000);
timing(_time * 1000);
});
};
//显示
this.show = function (title, text, time) {
if (title == 0 || !title) title = this.title;
this.inits(title, text);
if (time >= 0) this.time = time;

switch (this.anims.type) {
case 'slide': _obj.slideDown(this.anims.speed); break;
case 'fade': _obj.fadeIn(this.anims.speed); break;
case 'show': _obj.show(this.anims.speed); break;
default: _obj.slideDown(this.anims.speed); break;
}
this.rmmessage(this.time);
};
//设置宽高
this.lays = function (width, height) {
if (width != 0 && width) this.layer.width = width;
if (height != 0 && height) this.layer.height = height;
};
//呈现属性
this.anim = function (type, speed) {
if (type != 0 && type) this.anims.type = type;
if (speed != 0 && speed) {
switch (speed) {
case 'slow': ; break;
case 'fast': this.anims.speed = 200; break;
case 'normal': this.anims.speed = 400; break;
default: this.anims.speed = speed; break;
}
}
};
//移除层时间
this.rmmessage = function (time) {
if (time > 0) {
timer1 = setTimeout(function () { closeMsg(); }, time);
if (this.isTiming) {
timing(time);
}
}
};
//计时
timing = function (time) {
_time = time / 1000;
_timer2 = setInterval(function () {
_obj.find('.msg_bg_middle').find('font').html(_title + ' [' + (--_time) + '秒后自动关闭]');
}, 1000);
}
//关闭层
closeMsg = function () {
switch (_anims.type) {
case 'slide': _obj.slideUp(_anims.speed); break;
case 'fade': _obj.fadeOut(_anims.speed); break;
case 'show': _obj.hide(_anims.speed); break;
default: _obj.slideUp(_anims.speed); break;
}
setTimeout(function () { _obj.remove(); }, _anims.speed);
}
}

示例函数:

复制代码 代码如下:

var msg = '<p class="message_txt">当前有' + json.total + '个待审核用户等待您审核。</p><i>' + json.stadate + '</i>';
var msgDiv = new Messager();
msgDiv.isTiming = true;
msgDiv.lays(300, 180);
msgDiv.show("用户审核提醒", msg, 10000);

时间: 2024-09-05 05:43:34

javascript右下角弹层及自动隐藏(自己编写)_jquery的相关文章

Javascript 右下角弹出广告效果代码

广告代码  代码如下 复制代码 <!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> <meta http-equi

Javascript控制DIV层显示与隐藏两个实例

简单指向文字显示内容实例  代码如下 复制代码 <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>oec2003</title> <script language="JavaScript" type="text/JavaScript&quo

JQuery浮动DIV提示信息并自动隐藏的代码_jquery

复制代码 代码如下: /** * 浮动DIV定时显示提示信息,如操作成功, 失败等 * @param string tips (提示的内容) * @param int height 显示的信息距离浏览器顶部的高度 * @param int time 显示的时间(按秒算), time > 0 * @sample <a href="javascript:void(0);" onclick="showTips( '操作成功', 100, 3 );">点击

使用JavaScript实现弹出层效果的简单实例_javascript技巧

声明 阅读本文需要有一定的HTML.CSS和JavaScript基础 设计 实现弹出层效果的思路非常简单:将待显示的内容先隐藏,在触发某种条件后(如点击按钮),将原本隐藏的内容显示出来. 实现 <!DOCTYPE html> <html> <head> <title>Window对象</title> <meta charset="utf-8"> </head> <body> <a hr

jquery.boxy弹出框(后隔N秒后自动隐藏/自动跳转)_jquery

对于 Boxy弹出框的使用之前写过一些文章(查看jquery.boxy基础),今天主要是在解决一个需要之后,觉得值得把它记录下来,所以就再写一篇,主要功能是,在弹出对话框后,隔N秒后自动隐藏,还有就是自动跳转! 效果如图:  而所封装的代码如下: 复制代码 代码如下: // boxy对话框扩展 var Boxy_Extensions = { options: { title: '艺吧提示', closeText: 'x' }, //弹出后N秒后隐藏 alertDelayFun: function

JavaScript制作弹出层效果_javascript技巧

先给大家展示下效果图,效果图如下所示: 1.引用相关easyui.min.js,easyui-lang-zh_CN.js 等js 文件: 2.前台代码 <input type="text" id="txt_Type" style="display:none" /> <div class="macFormItem" id="divSQXLH" runat="server"

javascript控制层显示或隐藏的方法_javascript技巧

本文实例讲述了javascript控制层显示或隐藏的方法.分享给大家供大家参考.具体实现方法如下: <html> <head> <title>中国风</title> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> </head> <script language="JavaScript&qu

ajax制作网页右下角弹出提示效果

记得以前做自动提醒都是使用iframe框架,在一个框架里不停的刷新.检测是否有新的消息.但在使用类似于MSN的提醒中,弹出的提示框信息都是在iframe框架中显示.即当iframe框架不可见时,提示信息也就看不到.并且在整个页面效果上还的考虑一些浏览器对框架的支持.     使用ajax(动态网站静态化)技术,分两部分来说明.首先是后台的处理.这里我是在网上下载的ajax(动态网站静态化) dll文件(schwarz-interactive.de, Michael Schwarz,版本5.7.2

javascript-如何用JavaScript实现遮罩层并且可以指定位置高亮

问题描述 如何用JavaScript实现遮罩层并且可以指定位置高亮 想要用Javascript实现一个弹出的全网页遮罩层,并且这个遮罩层可以指定高亮位置,比如高亮被遮住的某一个<div>元素. 求教前端大神指点一二,给个例子什么的~~拜谢!![图片说明](http://img.ask.csdn.net/upload/201602/09/1455021686_557805.png) 解决方案 http://www.jb51.net/article/47593.htm 解决方案二: 我给你一个小例