LOGO OA教程 ERP教程 模切知识交流 PMS教程 CRM教程 开发文档 其他文档  
 
网站管理员

纯JS实现的超漂亮Tips文字提示框,可关闭

admin
2021年2月2日 17:11 本文热度 2887
<!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>
<title>Tips文字提示</title>
</head>
<body>
<style type="text/css">
body{ }
.lj-tipsWrap,.lj-in,.lj-close{display:inline-block;}
.lj-tipsWrap{background:#F4FBFF;line-height:1.5em;padding:5px 15px;border:1px solid #2192D3;position:absolute;text-align:left;}
.lj-in{position:absolute;zoom:1;border:10px dashed transparent;width:0px;height:0px;}
.lj-in span{zoom:1;width:0px;height:0px;overflow:hidden;}
.lj-close{position:absolute; text-decoration:none;color:#000; height:9px; width:9px; overflow:hidden;line-height:0.5em; right:0; top:0;}
.lj-close:hover{color:#39F;}
.lj-top{border-top:10px solid #2192D3;bottom:-20px; left:3px;}
.lj-top span{border-top:10px solid #F4FBFF;margin:-11px 0 0 -10px;}
.lj-right{border-right:10px solid #2192D3;left:-20px; top:3px;}
.lj-right span{border-right:10px solid #F4FBFF;margin:-10px 0 0 -9px;}
.lj-bottom{border-bottom:10px solid #2192D3;top:-20px; left:3px;}
.lj-bottom span{border-bottom:10px solid #F4FBFF;margin:-9px 0 0 -10px;}
.lj-left{border-left:10px solid #2192D3;right:-20px; top:3px; }
.lj-left span{border-left:10px solid #F4FBFF;margin:-10px 0 0 -11px;}
.lj-left ~ .lj-close{left:0;}
/*css 3渐强*/
.lj-tipsWrap{-webkit-border-radius:3px;-moz-border-radius:3px;-webkit-box-shadow:2px 2px 3px #eee;-moz-box-shadow:2px 2px 3px #eee;}
</style>
<script type="text/javascript">
window.ljtips=function(){var i=document.body,j=document.documentElement,n=/msie\s([\d\.]+)/.test(navigator.userAgent.toLowerCase()),k=window;return function(l){var c=l?typeof l=="string"?document.getElementById(l):l:this,d=null,s=c.offsetWidth,t=c.offsetHeight,m=0,g=null,e={},o={left:function(a){return{top:d.top,left:d.left-a-15}},top:function(a,h){return{top:d.top-h-15,left:d.left}},right:function(){return{top:d.top,left:d.left+s+15}},bottom:function(){return{top:d.top+t+15,left:d.left}}};e.show=
function(a){if(c.lock)c.lock=false;else{c.lock=true;d=c.getBoundingClientRect();var h=i.scrollTop+j.scrollTop,f=i.scrollLeft+j.scrollLeft;a.p=a.p||"right";var b=e.append(a.p,a.closeBtn||false);b.getElementsByTagName("DIV")[0].innerHTML=a.content;var p=o[a.p](b.offsetWidth,b.offsetHeight);b.style.top=p.top+h+"px";b.style.left=p.left+f+"px";a.time&&setTimeout(function(){e.clear(document.getElementById("lj"+m))},a.time);a.fn&&a.fn.call(c,document.getElementById("lj"+m));g=function(w,q){return function(){var u=
i.scrollTop+j.scrollTop,v=i.scrollLeft+j.scrollLeft;d=c.getBoundingClientRect();var r=o[a.p](b.offsetWidth,b.offsetHeight);q.style.top=r.top+u+"px";q.style.left=r.left+v+"px"}}(c,b);n?k.attachEvent("onresize",g):k.addEventListener("resize",g,false)}};e.append=function(a,h){var f=m=Math.floor(Math.random()*1E4),b=document.createElement("DIV");b.id="lj"+f;b.innerHTML=''<div class="lj-tipsWrap" id="tipsWrap-<%=r%>"><div></div><span class="lj-in lj-<%=p%>"><span class="lj-in"></span></span><a href="javascript:void(0)" id="ljClose<%=r%>" class="lj-close">x</a></div>''.replace("<%=p%>",
a).replace(/<%=r%>/g,f);document.body.appendChild(b);if(h)document.getElementById("ljClose"+f).onclick=e.hide;else document.getElementById("ljClose"+f).style.display="none";return document.getElementById("tipsWrap-"+f)};e.clear=function(a){a&&a.parentNode&&a.parentNode.removeChild(a);n?k.detachEvent("onresize",g):k.removeEventListener("resize",g,false);c.lock=false};e.hide=function(){e.clear(document.getElementById("lj"+m))};return e}}();
</script>
<h2>鼠标滑过或点击下面带方框的文字可看到效果:</h2>
<span style="display:inline-block; padding:5px; border:1px solid #CCC; margin:30px 30px 30px 100px;" id="test1">看我这里一个DIV</span><br/>
<input style="display:inline-block; padding:5px; border:1px solid #CCC; margin:30px 30px 30px 100px;" value="点击我"  id="test2"><br/>
<span style="display:inline-block; padding:5px; border:1px solid #CCC; margin:30px 30px 30px 100px;"  id="test3">提示在我的下面出现</span><br/>
<span style="display:inline-block; padding:5px; border:1px solid #CCC; margin:30px 30px 30px 100px;"  id="test4">提示在左边出现</span><br/>
<span style="display:inline-block; padding:5px; border:1px solid #CCC;margin:30px 30px 30px 100px;"  id="test5">提示出现2秒后会自动消失</span><br/>
<span style="display:inline-block; padding:5px; border:1px solid #CCC; margin:30px 30px 30px 100px;"  id="test6">提示可以有关闭按钮</span><br/>
<div style="text-align:center;">
<span style="display:inline-block; padding:5px; border:1px solid #CCC; margin:30px 30px 30px 100px;"  id="test7">不同担心页面放大缩小会位置会偏移哦</span><br/>
</div>
<h2>优点</h2>
<ul>
<li>1:兼容 各种浏览器</li>
<li>2:自己定义TIPS样式(颜色),CSS3渐进增强</li>
<li>3:多方向弹出提示</li>
<li>4:纯CSS+javascript(不包含任何图片)</li>
<li>5:体积超级小 CSS+js = 3k</li>
</ul>
<h2>参数配置</h2>
<ul>
<li>ljtips(object).show(JSON)</li>
<li>object: DOM对象ID(test1), DOM对象</li>
<li><pre>
json:{
content:提示的消息内容(必须),
p:提示框位置(可选值top left bottom right),默认为right(可选),
closeBtn:是否有关闭按钮(true false) 默认值(false)(可选),
time:多少毫秒提示框消失(可选)
}
</pre></li>
</ul>
<h3>使用说明</h3>
<ul>
<li>主要方法 .show(); .hide();.clear(); 一般你只需要使用show,hide;</li>
<li>使用1</li>
<li>首先实例化一个ljtips(var tips=ljtips(''test1'')); 然后使用tips.show(JSON)</li>
<li>使用2</li>
<li>在行内调用提示框“&lt;div onclick=&quot; ljtips(this).show(JSON); &quot;&gt;&lt;/div&gt;”</li>
<li>使用3</li>
<li>在JS里调用document.getElementById("test6").onmouseover = function(){ljtips(this).show({content:"这个框你关不掉了吧!没有关闭按钮!",p:''right''})};</li>
</ul>
<script type="text/javascript">
var test1 = ljtips(''test1'');
document.getElementById("test1").onmouseover = function(){test1.show({content:"鼠标划过时候的TIPS...<br/>兼容主流浏览器 IE 6 7 8 chorme Firefox Opera Safari"})};
document.getElementById("test1").onmouseout = function(){test1.hide();};
document.getElementById("test2").onfocus = function(){ljtips(this).show({content:"这个提示会在<br/>input的上方!有个关闭按钮哦",p:''top'',closeBtn:true})};
document.getElementById("test3").onmouseover = function(){ljtips(this).show({content:"我在下面出现了!不要认为会用到图片哦!",p:''bottom'',closeBtn:true})};
document.getElementById("test4").onmouseover = function(){ljtips(this).show({content:"我可以在4个方向上",p:''left'',closeBtn:true})};
document.getElementById("test5").onmouseover = function(){ljtips(this).show({content:"提示出现2秒后会自动消失",p:''bottom'',time:2000})};
document.getElementById("test6").onmouseover = function(){ljtips(this).show({content:"这个框你关不掉了吧!没有关闭按钮!",p:''right''})};
document.getElementById("test7").onmouseover = function(){ljtips(this).show({content:"您可以放大或者缩小浏览器窗口!<br/>他会跟随这个绝对位置,不会有丝毫偏差。",p:''right'',closeBtn:true})};
</script>
</body>
</html>

该文章在 2021/2/2 17:11:47 编辑过

全部评论1

admin
2021年2月2日 17:12
Tips文字提示

鼠标滑过或点击下面带方框的文字可看到效果:

看我这里一个DIV

提示在我的下面出现
提示在左边出现
提示出现2秒后会自动消失
提示可以有关闭按钮
不同担心页面放大缩小会位置会偏移哦

优点

  • 1:兼容 各种浏览器
  • 2:自己定义TIPS样式(颜色),CSS3渐进增强
  • 3:多方向弹出提示
  • 4:纯CSS+javascript(不包含任何图片)
  • 5:体积超级小 CSS+js = 3k

参数配置

  • ljtips(object).show(JSON)
  • object: DOM对象ID(test1), DOM对象
  • 	json:{
    		content:提示的消息内容(必须),
    		p:提示框位置(可选值top left bottom right),默认为right(可选),
    		closeBtn:是否有关闭按钮(true false) 默认值(false)(可选),
    		time:多少毫秒提示框消失(可选)
    	}
    	

使用说明

  • 主要方法 .show(); .hide();.clear(); 一般你只需要使用show,hide;
  • 使用1
  • 首先实例化一个ljtips(var tips=ljtips(''test1'')); 然后使用tips.show(JSON)
  • 使用2
  • 在行内调用提示框“<div onclick=" ljtips(this).show(JSON); "></div>”
  • 使用3
  • 在JS里调用document.getElementById("test6").onmouseover = function(){ljtips(this).show({content:"这个框你关不掉了吧!没有关闭按钮!",p:''right''})};
关键字查询
相关文章
正在查询...
点晴ERP是一款针对中小制造业的专业生产管理软件系统,系统成熟度和易用性得到了国内大量中小企业的青睐。
点晴PMS码头管理系统主要针对港口码头集装箱与散货日常运作、调度、堆场、车队、财务费用、相关报表等业务管理,结合码头的业务特点,围绕调度、堆场作业而开发的。集技术的先进性、管理的有效性于一体,是物流码头及其他港口类企业的高效ERP管理信息系统。
点晴WMS仓储管理系统提供了货物产品管理,销售管理,采购管理,仓储管理,仓库管理,保质期管理,货位管理,库位管理,生产管理,WMS管理系统,标签打印,条形码,二维码管理,批号管理软件。
点晴免费OA是一款软件和通用服务都免费,不限功能、不限时间、不限用户的免费OA协同办公管理系统。
Copyright 2010-2024 ClickSun All Rights Reserved