[文章目录]显示/隐藏
在我以前的博客发过
这次跟上次不同
主要评论区看IP和版本,没这个提示功能,
感觉怪怪的,所以折腾了一下,
效果看我的评论区
使用方法
使用比较绿色的做法,
提示工具的样式使用CSS自定义,
jQuery只是定义显示的位置.
所以需要在引进插件的同时,
也要增加一点样式.
jQuery代码
- ! function(a) {
- a.fn.toolTip = function(b) {
- return this.each(function() {
- function m(b) {
- var c = a("#" + k);
- c.css({
- top: b.pageY + parseInt(j),
- left: b.pageX + parseInt(i)
- }).show("fast"), null != h && (h.indexOf("left") >= 0 && c.css({
- left: "auto",
- right: f - parseInt(b.pageX) + parseInt(i)
- }), h.indexOf("top") >= 0 && c.css({
- top: b.pageY - parseInt(g) - parseInt(j)
- }))
- }
- var c = {
- positionPro: "position",
- positionValue: null,
- positionX: "10",
- positionY: "20",
- tipEle: "tooltip",
- tipText: "title",
- tipFlag: !0
- }, d = a.extend({}, c, b),
- e = a(this),
- f = a(window).width(),
- g = e.outerHeight(),
- h = void 0 != e.attr(d.positionPro) ? e.attr(d.positionPro) : d.positionValue,
- i = void 0 != e.attr("positionX") ? e.attr("positionX") : d.positionX,
- j = void 0 != e.attr("positionY") ? e.attr("positionY") : d.positionY,
- k = d.tipEle,
- l = e.attr(d.tipText);
- 0 != d.tipFlag && void 0 != e.attr(d.tipText) && e.on("mouseover", function(b) {
- if (a(this), this.title = "", void 0 != l) {
- var d = "<div id='" + k + "'><p>" + l + "</p></div>";
- a("body").append(d)
- }
- m(b)
- }).on("mouseout", function() {
- this.title = l, a("#" + k).remove()
- }).on("mousemove", function(a) {
- m(a)
- })
- })
- }
- }(jQuery);
加载效果
- <script>
- $(function(){
- $("#links a").toolTip(); // #links 改成你的需要的 id 或者 class
- })
- </script>
css样式
- #tooltip{position:absolute;z-index:1000;max-width:300px;width:auto;margin:0; padding:0;background:#181818; opacity: .8;}
- #tooltip p{padding:5px 10px; margin:0;color:#FFFFFF;font-family:Arial,Helvetica,Sans-serif;}
教程结束
大家去试试吧