引用

项目中需要一个信息提示的功能,就上网找了一个插件,发现colortip实现比较简单,就定了这个插件。

实现过程

官网:http://tutorialzine.com/2010/07/colortips-jquery-tooltip-plugin/

最终要实现的效果:

colortip是将标签中的title属性的值弹出显示的,默认情况是黄色的:

 <!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<!--css文件-->
<link href="Colortip/styles.css" rel="stylesheet" />
<link href="Colortip/colortip-1.0/colortip-1.0-jquery.css" rel="stylesheet" />
</head>
<body>
<div style="text-align:center;margin-top:200px;"><a href="#" title="这是个大美女">美女</a></div>
<div style="text-align:center;margin-top:250px;"><a href="#" title="这是个大美女" class="black">美女</a></div>
</body>
</html>
<!--引入需要的js-->
<script type="text/javascript" src="Script/jquery-1.11.0.js"></script>
<script type="text/javascript" src="Colortip/colortip-1.0/colortip-1.0-jquery.js"></script>
<script type="text/javascript" src="Colortip/script.js"></script>

效果:

通过查看这些设置,是在colortip-1.0-jquery.js文件中进行配置的:

(function($){
$.fn.colorTip = function(settings){ var defaultSettings = {
color : 'yellow',//默认颜色
timeout : 500
} var supportedColors = ['red','green','blue','white','yellow','black'];//总共有6种主题的颜色 /* Combining the default settings object with the supplied one */
settings = $.extend(defaultSettings,settings); /*
* Looping through all the elements and returning them afterwards.
* This will add chainability to the plugin.
*/ return this.each(function(){ var elem = $(this); // If the title attribute is empty, continue with the next element
if(!elem.attr('title')) return true; // Creating new eventScheduler and Tip objects for this element.
// (See the class definition at the bottom). var scheduleEvent = new eventScheduler();
var tip = new Tip(elem.attr('title')); // Adding the tooltip markup to the element and
// applying a special class: elem.append(tip.generate()).addClass('colorTipContainer'); // Checking to see whether a supported color has been
// set as a classname on the element. var hasClass = false;
for(var i=0;i<supportedColors.length;i++)
{
if(elem.hasClass(supportedColors[i])){
hasClass = true;
break;
}
} // If it has been set, it will override the default color if(!hasClass){
elem.addClass(settings.color);
} // On mouseenter, show the tip, on mouseleave set the
// tip to be hidden in half a second. elem.hover(function(){ tip.show(); // If the user moves away and hovers over the tip again,
// clear the previously set event: scheduleEvent.clear(); },function(){ // Schedule event actualy sets a timeout (as you can
// see from the class definition below). scheduleEvent.set(function(){
tip.hide();
},settings.timeout); }); // Removing the title attribute, so the regular OS titles are
// not shown along with the tooltips. elem.removeAttr('title');
}); } /*
/ Event Scheduler Class Definition
*/ function eventScheduler(){} eventScheduler.prototype = {
set : function (func,timeout){ // The set method takes a function and a time period (ms) as
// parameters, and sets a timeout this.timer = setTimeout(func,timeout);
},
clear: function(){ // The clear method clears the timeout clearTimeout(this.timer);
}
} /*
/ Tip Class Definition
*/ function Tip(txt){
this.content = txt;
this.shown = false;
} Tip.prototype = {
generate: function(){ // The generate method returns either a previously generated element
// stored in the tip variable, or generates it and saves it in tip for
// later use, after which returns it. return this.tip || (this.tip = $('<span class="colorTip">'+this.content+
'<span class="pointyTipShadow"></span><span class="pointyTip"></span></span>'));//显示的消息提示框是一个span标签
},
show: function(){
if(this.shown) return; // Center the tip and start a fadeIn animation
this.tip.css('margin-left',-this.tip.outerWidth()/2).fadeIn('fast');
this.shown = true;
},
hide: function(){
this.tip.fadeOut();
this.shown = false;
}
} })(jQuery);

通过该js文件,可见该插件主要是在title属性中设置显示信息的。

总结

colortip用起来还是非常简单的,在想要提示信息的地方加个带title属性的a标签就可以了,不过有点差强人意的地方,如果其他的标签例如按钮,加一个title,就会提示错误。

[js插件]分享一个文章内容信息提示插件Colortip的更多相关文章

  1. 仿网易邮箱5.0(四):信息提示插件(tips.js)

    信息提示插件,在平常的开发中也是经常乃至的一个插件,像是一些辅助信息的提示,如:加载成功.提交信息成功或失败等等.这个插件在163邮箱中用在切换标签时提示加载状态. 下面我们先来分析一下这个小插件需要 ...

  2. 分享一个JQuery弹出层插件

    JQuery插件TipsWindown 1.1 一个基于jQuery的弹出层.支持拖拽,支持内容为文字,图片,URL等!至于兼容性.在IE6下,弹出对像无法绝对固定.其他应该没啥大问题: 最新更新:( ...

  3. 自己写的一个简单的jQuery提示插件

    代码: /** * 2014年11月13日 * 提示插件 */ (function ($) { $.fn.tips = function (text) { var divtipsstyle = &qu ...

  4. JS~Boxy和JS模版实现一个标准的消息提示框

    面向对象的封装 面向对象一个入最重要的特性就是“封装”,将一些没有必要公开的方法和属性以特定的方式进行组装,使它对外只公开一个接口,外界在调用它时,不需要关注它实现的细节,而只要关注它的方法签名即可, ...

  5. windows下使用python的scrapy爬虫框架,爬取个人博客文章内容信息

    scrapy作为流行的python爬虫框架,简单易用,这里简单介绍如何使用该爬虫框架爬取个人博客信息.关于python的安装和scrapy的安装配置请读者自行查阅相关资料,或者也可以关注我后续的内容. ...

  6. 分享一个Visual Studio的背景插件,让堆码更富情趣

    忘记一件重要的事情,我使用的是VS 2012版,其他更高版本应该是可以找到的,以下版本就不清楚了.有可能找不到,见谅,也不是我开发的,只是偶尔碰到,拿出来让大家知道. 上周某日,新生命群里面还是一如既 ...

  7. 分享一个jQuery动态网格布局插件:Masonry(转)

    在线演示 Masonry是 一款非常强大的jQuery动态网格布局插件,可以帮助开发人员快速开发类似剪贴画的界面效果.和CSS中float的效果不太一样的地方在 于,float先水平排列,然后再垂直排 ...

  8. 分享一个废弃已久的插件架构 (.Net)

    框架介绍 1:将插件暴露的页面数据接口复用到任何 WebForm和Mvc 架构的系统. 2:插件可在线卸载,发布,更新. 3:插件可分布式 独立 部署. 4:插件之间完全解耦,通过Url跳转 相互不需 ...

  9. 今天再分享一个TextView内容风格化的类

    /* * Copyright (C) 2014 Jason Fang ( ijasonfang@gmail.com ) * * Licensed under the Apache License, V ...

随机推荐

  1. mysql 创建数据库的时候选择 utf8 bin 和 utf8 ci的区别

    utf8 ci  不区分大小写: utf8 bin 区分大小写:

  2. Synergy,一个软件团队质量改进之路之一 --- 规划

    关于质量改进 ISO9001:2000的核心思想是持续改进 ISO关于质量管理有8项原则: 原则一: 以顾客为关注焦点 原则二: 领导作用 原则三: 全员参与 原则四: 过程方法 原则五:管理的系统方 ...

  3. Tutorial: Reverse debugging with GDB 7 (转载)

    Tutorial: Reverse debugging with GDB 7 Tutorial: Reverse debugging with GDB 7 by Jay Conrod posted o ...

  4. 长安大学第四届ACM-ICPC“迎新杯”程序设计竞赛-重现赛 F - 打铁的箱子

    题目描述 作为彩虹岛上最擅长打铁的人,

  5. 洛谷P4151 [WC2011] 最大XOR和路径 [线性基,DFS]

    题目传送门 最大XOR和路径 格式难调,题面就不放了. 分析: 一道需要深刻理解线性基的题目. 好久没打过线性基的题了,一开始看到这题还是有点蒙逼的,想了几种方法全被否定了.还是看了大佬的题解才会做的 ...

  6. 我对于react-router路由原理的学习

    目录 react-router依赖基础--history react-router是如何实现URL与UI同步 一 react-router依赖基础--history history是一个独立的第三方j ...

  7. Redux学习之解读applyMiddleware源码深入middleware工作机制

    随笔前言 在上一周的学习中,我们熟悉了如何通过redux去管理数据,而在这一节中,我们将一起深入到redux的知识中学习. 首先谈一谈为什么要用到middleware 我们知道在一个简单的数据流场景中 ...

  8. 【HDU 6020】 MG loves apple (乱搞?)

    MG loves apple  Accepts: 20  Submissions: 693  Time Limit: 3000/1500 MS (Java/Others)  Memory Limit: ...

  9. eclipse 怎么 直接查看 文件所在位置 显示在文件管理器中。用浏览器浏览。

    韩梦飞沙  韩亚飞  313134555@qq.com  yue31313  han_meng_fei_sha eclipse 怎么 直接查看 文件所在位置 显示在文件管理器中.用浏览器浏览.

  10. 51nod1821 最优集合 贪心

    首先考虑一个集合的最大优美值怎么求出 考虑新增一个数,假设我们现在的优美值已经达到了$V$,那么只需要一个$[1, V + 1]$的数就可以使$V$达到更大 为了保证能添加尽可能多的数进来,我们这么构 ...