tooltip提示插件

简介: tooltip提示信息插件原理:定位元素在页面中的位置即坐标信息,将显示节点元素插入到body中绝对应为到相应位置,显示内容从指定元素的属性(dataMess)中获取或者通过设置获取。使用方法: $("#test").

tooltip提示信息插件

原理:定位元素在页面中的位置即坐标信息,将显示节点元素插入到body中绝对应为到相应位置,显示内容从指定元素的属性(dataMess)中获取或者通过设置获取。


使用方法:

$("#test").iTooltip({"posType":"top"}); 
<div id="test" class="test" dataMess="测试数据中。。。<br/>测试数据中。。。">测试</div>



<!DOCTYPE html> <html> <head> <meta charset="UTF-8" /> <title>tooltip提示插件</title> <style>.iTooltipMes{ position: absolute; display: block; color: #000; font-size: 12px; padding: 10px; background: #fff; border: 1px solid #999; border-radius: 3px; box-shadow: 0px 1px 3px rgba(0,0,0,0.3); z-index: 999999; } .iToolTri{ position: absolute; z-index: 1; display: block; width: 0px; height: 0px; font-size: 0px; line-height: 0px; border: 8px solid #999999; } .iToolTri i{ position: absolute; z-index: 1; display: block; width: 0px; height: 0px; font-size: 0px; line-height: 0px; border: 6px solid #ffffff; } .iToolTriTop{ left: 50%; bottom: -16px; margin-left: -8px; border-color: #999999 transparent transparent transparent; border-style: solid dashed dashed dashed; } .iToolTriTop i{ left: -6px; bottom: -4px; border-color: #ffffff transparent transparent transparent; border-style: solid dashed dashed dashed; } .iToolTriBtm{ left: 50%; top: -16px; margin-left: -8px; border-color: transparent transparent #999999 transparent; border-style: dashed dashed solid dashed; } .iToolTriBtm i{ left: -6px; top: -4px; border-color: transparent transparent #ffffff transparent; border-style: dashed dashed solid dashed; } .iToolTriRt{ left: -16px; top: 50%; margin-top: -8px; border-color: transparent #999999 transparent transparent ; border-style: dashed solid dashed dashed ; } .iToolTriRt i{ left: -4px; top: -6px; border-color: transparent #ffffff transparent transparent; border-style: dashed solid dashed dashed; } .iToolTriLt{ right: -16px; top: 50%; margin-top: -8px; border-color: transparent transparent transparent #999999; border-style: dashed dashed dashed solid; } .iToolTriLt i{ right: -4px; top: -6px; border-color: transparent transparent transparent #ffffff; border-style: dashed dashed dashed solid; } .animated { -webkit-animation-duration: 0.3s; animation-duration: 0.3s; -webkit-animation-fill-mode: both; animation-fill-mode: both; } .animated.hinge { -webkit-animation-duration: 0.6s; animation-duration: 0.6s; } @-webkit-keyframes fadeInDown { 0% { opacity: 0; -webkit-transform: translateY(-20px); transform: translateY(-20px); } 100% { opacity: 1; -webkit-transform: translateY(0); transform: translateY(0); } } @keyframes fadeInDown { 0% { opacity: 0; -webkit-transform: translateY(-20px); -ms-transform: translateY(-20px); transform: translateY(-20px); } 100% { opacity: 1; -webkit-transform: translateY(0); -ms-transform: translateY(0); transform: translateY(0); } } .fadeInDown { -webkit-animation-name: fadeInDown; animation-name: fadeInDown; } @-webkit-keyframes fadeInLeft { 0% { opacity: 0; -webkit-transform: translateX(-20px); transform: translateX(-20px); } 100% { opacity: 1; -webkit-transform: translateX(0); transform: translateX(0); } } @keyframes fadeInLeft { 0% { opacity: 0; -webkit-transform: translateX(-20px); -ms-transform: translateX(-20px); transform: translateX(-20px); } 100% { opacity: 1; -webkit-transform: translateX(0); -ms-transform: translateX(0); transform: translateX(0); } } .fadeInLeft { -webkit-animation-name: fadeInLeft; animation-name: fadeInLeft; } @-webkit-keyframes fadeInUp { 0% { opacity: 0; -webkit-transform: translateY(20px); transform: translateY(20px); } 100% { opacity: 1; -webkit-transform: translateY(0); transform: translateY(0); } } @keyframes fadeInUp { 0% { opacity: 0; -webkit-transform: translateY(20px); -ms-transform: translateY(20px); transform: translateY(20px); } 100% { opacity: 1; -webkit-transform: translateY(0); -ms-transform: translateY(0); transform: translateY(0); } } .fadeInUp { -webkit-animation-name: fadeInUp; animation-name: fadeInUp; } @-webkit-keyframes fadeInRight { 0% { opacity: 0; -webkit-transform: translateX(20px); transform: translateX(20px); } 100% { opacity: 1; -webkit-transform: translateX(0); transform: translateX(0); } } @keyframes fadeInRight { 0% { opacity: 0; -webkit-transform: translateX(20px); -ms-transform: translateX(20px); transform: translateX(20px); } 100% { opacity: 1; -webkit-transform: translateX(0); -ms-transform: translateX(0); transform: translateX(0); } } .fadeInRight { -webkit-animation-name: fadeInRight; animation-name: fadeInRight; } </style> <script src="http://files.cnblogs.com/kuikui/jquery-1.10.2.min.js"></script> <style > *{margin: 0px;padding: 0px;} body{position: relative;height: 1500px; font-size: 14px; } .test{position: absolute; width: 100px; height: 30px; line-height: 30px; text-align: center; border: 1px solid #f0f; cursor: pointer;} .left{ left: 10px; top: 10px;} .top{ left: 50%; top: 10px; margin-left: -50px;} .right{right: 10px; top: 10px;} .bottom{left: 50%; bottom: 10px; margin-left: -50px;} .center{left: 50%; top: 50%; margin-left: -50px; margin-top: -15px;} </style> </head> <body> <div id="left" class="test left" dataMess="测试数据中。。。<br/>测试数据中。。。">测试左</div> <div id="top" class="test top" dataMess="测试数据中。。。<br/>测试数据中。。。">测试上</div> <div id="right" class="test right" dataMess="测试数据中。。。<br/>测试数据中。。。">测试右</div> <div id="bottom" class="test bottom" dataMess="测试数据中。。。<br/>测试数据中。。。">测试下</div> <div id="center" class="test center" dataMess="http://www.cnblogs.com/kuikui<br/>测试数据中。。。">测试中</div> <script>(function($, window, document) { var pluginName = "iTooltip", defaults = { addClass: "", dataMess: "", posType: "top" // [left|top|right|bottom] }; function Plugin(element, options) { var options = $.extend({}, defaults, options); this.opts = options; this.$elem = element; this.elem = element.selector; this.anis = {top:"fadeInDown",right:"fadeInLeft",bottom:"fadeInUp",left:"fadeInRight"}; this.tris = {top:"iToolTriTop",right:"iToolTriRt",bottom:"iToolTriBtm",left:"iToolTriLt"}; this.isOk = true; this.tmpPosType = null; this.init(); }; Plugin.prototype = { init: function() { var _this = this; $(document).on("mouseover", _this.elem, function() { var $this = $(this); if (_this.isOk) { _this.isOk = false; _this.setShow($this); } }); $(document).on("mouseout", _this.elem, function() { if(!_this.isOk){ _this.isOk = true; _this.tmpPosType = _this.opts.posType; $(".iTooltipMes").remove(); } }); }, setShow: function(obj) { var _this = this; var l = obj.offset().left; var t = obj.offset().top; var w = obj.width(); var h = obj.height(); var mess = _this.opts.dataMess || obj.attr("dataMess"); var tmpHtml = "<div class='iTooltipMes animated'>" + mess + "<i class='iToolTri'><i></i></i></div>"; $("body").append(tmpHtml); var iTooltipMes = $(".iTooltipMes"); var ow = iTooltipMes.outerWidth(); var oh = iTooltipMes.outerHeight(); var tmpt = 0; var tmpl = 0; var distance = 10; var win = $(window); var winW = win.width(); var winH = win.height(); var winTop = win.scrollTop(); if( t < (h + distance + winTop) && _this.opts.posType ==="top"){ _this.tmpPosType = "bottom"; } if((l+w+ow > winW) && _this.opts.posType ==="right"){ _this.tmpPosType = "left"; } if((l< ow ) && _this.opts.posType ==="left"){ _this.tmpPosType = "right"; } if( ((t - winH + oh) > winTop) && _this.opts.posType ==="bottom"){ _this.tmpPosType = "top"; } _this.tmpPosType = _this.tmpPosType || _this.opts.posType; switch(_this.tmpPosType){ case "top": tmpt = t - oh - distance; tmpl = l + ((w-ow)/2); break; case "right": tmpt = t - ((oh-h)/2) ; tmpl = l + w + distance; break; case "bottom": tmpt = t + h + distance; tmpl = l + ((w-ow)/2); break; case "left": tmpt = t - ((oh-h)/2); tmpl = l - ow - distance; break; default: break; } if(!!_this.opts.addClass){ iTooltipMes.addClass(_this.opts.addClass); } iTooltipMes.addClass(_this.anis[_this.tmpPosType]).css({ left: tmpl + "px", top: tmpt + "px" }).find(".iToolTri").addClass(_this.tris[_this.tmpPosType]); } }; $.fn[pluginName] = function() { var args = arguments; if(!$(this).selector){ return; } $(this).data("iTooltip", new Plugin(this, args[0])); } })(jQuery, window, document);</script> <script type="text/javascript"> $("#left").iTooltip({ "posType":"right"}); $("#top").iTooltip({ "posType":"bottom"}); $("#right").iTooltip({ "posType":"left"}); $("#bottom").iTooltip({ "posType":"top"}); $("#center").iTooltip({ "posType":"top"}); </script> </body> </html>

目录
相关文章
|
6月前
|
JavaScript 前端开发
【vue】iview如何把input输入框和点击输入框之后的边框去掉
【vue】iview如何把input输入框和点击输入框之后的边框去掉
140 0
|
3月前
|
JavaScript
Vue2文字提示(Tooltip)
这篇文章介绍了如何在Vue 3框架中创建一个文字提示组件(Tooltip),允许自定义提示框的最大宽度、展示文本和提示文本,支持鼠标悬停显示和隐藏效果。
161 0
Vue2文字提示(Tooltip)
|
JavaScript
ant design vue 设置表格选择框,全选按钮选不全
ant design vue 设置表格选择框,全选按钮选不全
1557 0
|
3月前
Vue3文字提示(Tooltip)
这是一篇关于 Vue2 文字提示(Tooltip)组件的教程,支持多种自定义属性,如最大宽度、展示文本、提示文本、样式、背景色、箭头显示等,并提供了在线预览示例。组件通过监听插槽和 `requestAnimationFrame` 实现了延迟显示与隐藏效果。文章详细介绍了组件实现代码及在页面中的使用方法。
117 0
Vue3文字提示(Tooltip)
|
4月前
|
JavaScript
vue element MessageBox.prompt this.$prompt组件禁止显示右上角关闭按钮,取消按钮,及点击遮罩层关闭
vue element MessageBox.prompt this.$prompt组件禁止显示右上角关闭按钮,取消按钮,及点击遮罩层关闭
83 0
|
6月前
|
移动开发 JavaScript 小程序
uView Tooltip 长按提示
uView Tooltip 长按提示
58 1
|
6月前
|
测试技术
【sgAutocomplete】自定义组件:基于elementUI的el-autocomplete组件开发的自动补全下拉框组件(带输入建议的自动补全输入框)
【sgAutocomplete】自定义组件:基于elementUI的el-autocomplete组件开发的自动补全下拉框组件(带输入建议的自动补全输入框)
uniapp u-tabs表单如何默认选中
uniapp u-tabs表单如何默认选中
491 0
饿了么UI按钮禁用时加文字提示,按钮正常时不加文字提示(el-tooltip使用注意事项)
饿了么UI按钮禁用时加文字提示,按钮正常时不加文字提示(el-tooltip使用注意事项)
294 0
|
JavaScript 前端开发 程序员
解决elementui中el-dropdown下拉菜单禁用项没有鼠标悬浮禁用样式
解决elementui中el-dropdown下拉菜单禁用项没有鼠标悬浮禁用样式
741 0