qTip2是一个灰常强大且精致的jQuery提示信息插件,是qTip的第2版,也是一个全新的版本,提供了丰富的功能及漂亮的外观,非常易于使用。
qTip2采用了MIT/GPLv2许可,官方网站为:http://craigsworks.com/projects/qtip2/,目前还没发布一个稳定版,Nightly版本经常会更新,当然这并不影响正常使用。
简介
若不放心可以尝试旧版的qTip,但在一些参数上会有所不同;若是从qTip升级到qTip2,可以使用官方提供的转换工具来升级你的代码:http://craigsworks.com/projects/qtip2/converter/。
如果使用时出现问题,那么直接下载以下3个文件吧,至少官方演示很正常:
从官方网站下载最新版本时,可以选择相应的样式及插件;可选的样式包括几种色彩风格(Colour Styles)、CSS3相关样式如圆角;以及以下各种插件,可根据自己需要选择:
- Ajax,这个不用说,请求远程内容的
- Tips,气泡对话效果,如箭头
- Modal,模态对话框效果,如jQuery UI Dialog / ThickBox 的效果
- Image map,提供对map内area标记的提示支持
- SVG,对SVG元素提供提示的支持
- BGIFrame,用于IE6这种古董,如遮住select控件等
除了以上插件的功能外,它的主要功能有(仅列出较常用的):
- 设置提示的内容、标题、关闭按钮等
- 使用元素的属性,来作为提示信息内容,如链接的标题(<a title="提示信息")、图片的提示(<img src="提示信息")等等
- 提示信息显示的位置
- 提示信息的目标,即显示到什么元素上
- 提示信息显示/隐藏触发的事件,如鼠标移到元素上、点击(mouseenter,click)
- 提示信息显示/隐藏的效果
- 外观的定义,通过相应样式设置
- 跟随可拖动目标、鼠标指针等
使用方法
以下就简单演示一些使用方法
创建一个最简单的提示:
1
2
3
|
$( "#demo2" ).qtip({
content: "这是提示内容(by囧月)"
});
|
创建一个带标题的提示:
1
2
3
4
5
6
|
$( "#demo3" ).qtip({
content: {
text: "这是提示内容(by囧月 lwme.cnblogs.com)"
, title: "提示标题"
}
});
|
带关闭按钮的提示:
1
2
3
4
5
6
7
8
9
|
$( "#demo3" ).qtip({
content: {
text: "这是提示内容(by囧月 lwme.cnblogs.com)"
, title: {
text: "提示标题"
, button: "关闭"
}
}
});
|
使用元素的属性作为提示信息:
1
2
3
|
$( "a[title]" ).qtip();
$( "img[alt]" ).qtip();
$( "div[title]" ).qtip();
|
也可以显式指定元素属性作为提示信息:
1
2
3
4
5
|
$( 'img[alt]' ).qtip({
content: {
attr: 'alt'
}
});
|
使用AJAX请求远程:
1
2
3
4
5
6
7
8
|
$( "#demo4" ).qtip({
content: {
text: "加载中..." ,
ajax: {
url: "lwmeAtCnblogs.aspx?name=囧月"
}
}
});
|
设置位置及样式:
1
2
3
4
5
6
7
8
9
|
$( "#demo5" ).qtip({
position: {
my: 'bottom left' ,
at: 'top center'
},
style: {
classes: 'ui-tooltip-red'
}
});
|
点击时出现模态对话框:
1
2
3
4
5
6
7
8
9
|
$( 'button' ).qtip({
content: "这是提示内容(by囧月 lwme.cnblogs.com)" ,
show: {
event: 'click' ,
solo: true ,
modal: true
},
hide: false
});
|
页面加载完成时显示,且不会自动隐藏:
1
2
3
4
5
6
7
|
$( 'button' ).qtip({
content: "这是提示内容(by囧月 lwme.cnblogs.com)" ,
show: {
ready: true
},
hide: false
});
|
参数设置
先看一下qTip2默认的参数设置:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
|
$.fn.qtip.defaults = {
prerender: false ,
id: false ,
overwrite: true ,
suppress: true ,
content: {
text: true ,
attr: 'title' ,
ajax: false ,
title: {
text: false ,
button: false
}
},
position: {
my: 'top left' ,
at: 'bottom right' ,
target: FALSE,
container: FALSE,
viewport: FALSE,
adjust: {
x: 0, y: 0,
mouse: TRUE,
resize: TRUE,
method: 'flip flip'
},
effect: function (api, pos, viewport) {
$( this ).animate(pos, {
duration: 200,
queue: FALSE
});
}
},
show: {
target: false ,
event: 'mouseenter' ,
effect: true ,
delay: 90,
solo: false ,
ready: false ,
modal: {
on: false ,
effect: true ,
blur: true ,
escape: true
}
},
hide: {
target: false ,
event: 'mouseleave' ,
effect: true ,
delay: 0,
fixed: false ,
inactive: false ,
leave: 'window' ,
distance: false
},
style: {
classes: '' ,
widget: false ,
width: false ,
height: false ,
tip: {
corner: true ,
mimic: false ,
width: 8,
height: 8,
border: true ,
offset: 0
}
},
events: {
render: null ,
move: null ,
show: null ,
hide: null ,
toggle: null ,
visible: null ,
focus: null ,
blur: null
}
};
|
看起来是很多,但是使用频率最高的估计也就以下这些参数:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
$.fn.qtip.defaults = {
content: {
text: true ,
attr: 'title' ,
ajax: false ,
title: {
text: false ,
button: false
}
},
position: {
my: 'top left' ,
at: 'bottom right' ,
},
show: {
event: 'mouseenter' ,
solo: false ,
ready: false ,
modal: false
},
hide: {
event: 'mouseleave'
},
style: 'ui-tooltip-default'
};
|
对于显示的位置,有以下参数可以设置:
1
2
3
4
5
6
7
8
9
10
11
12
|
my = [
'top left' , 'top right' , 'top center' ,
'bottom left' , 'bottom right' , 'bottom center' ,
'right center' , 'right top' , 'right bottom' ,
'left center' , 'left top' , 'left bottom' , 'center'
]
at = [
'bottom left' , 'bottom right' , 'bottom center' ,
'top left' , 'top right' , 'top center' ,
'left center' , 'left top' , 'left bottom' ,
'right center' , 'right top' , 'right bottom' , 'center'
]
|
而对于显示的色彩风格则有以下各种颜色:
1
|
[ 'red' , 'blue' , 'dark' , 'light' , 'green' , 'jtools' , 'plain' , 'youtube' , 'cluetip' , 'tipsy' , 'tipped' ]
|
比如red就是ui-tooltip-red,默认为default。另外还有ui-tooltip-shadow、ui-tooltip-rounded分别表示阴影、圆角效果,可以叠加,如下:
1
2
3
4
5
6
|
$( "#demo2" ).qtip({
content: "这是提示内容(by囧月)"
, style: {
classes: 'ui-tooltip-red ui-tooltip-shadow ui-tooltip-rounded'
}
});
|
另外对于ajax则有以下主要参数可以设置(与jQuery.ajax一致):
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
$( '.selector' ).qtip({
content: {
text: 'Loading...' ,
ajax: {
url: '/path/to/file' ,
type: 'GET' ,
data: { id: 3 },
dataType: 'json' ,
success: function (data, status) {
}
}
}
});
|
需要注意的是,AJAX默认使用GET请求而且启用了cache。
结尾
关于qTip2就介绍到这里,更多信息请参阅以下链接:
官方网站:http://craigsworks.com/projects/qtip2/
在线演示:http://craigsworks.com/projects/qtip2/demos/
官方文档:http://craigsworks.com/projects/qtip2/docs/
最后,放一个简单的DEMO。
转载
作者:囧月
出处:http://lwme.cnblogs.com/
分享到:
相关推荐
qTip2 精致的jQuery提示信息插件
主要介绍了jQuery提示插件qTip2用法,结合实例形式分析了qTip2的使用技巧,可支持ajax及多种样式的设置,需要的朋友可以参考下
jQuery qtip浮动提示框插件新浪微博图片或文字ajax提示
JQuery的前端气泡插件,包括js工具类及详细的使用实例,有注详细的注释
qTip是一个基于JQuery的Tooltip插件。它几乎支持所有的主流浏览器。
主要介绍了jquery.qtip提示信息插件用法,结合简单实例形式分析了该插件用于显示提示信息的相关使用技巧,具有一定参考借鉴价值,需要的朋友可以参考下
jquery qtip
jQuery qtip浮动提示框插件新浪微博图片或文字ajax提示框
qTip2是一个灰常强大且精致的jQuery提示信息插件,是qTip的第2版,也是一个全新的版本,提供了丰富的功能及漂亮的外观,非常易于使用
jquery-qtip,提示框。 使用很方便
jquery.qtip-1.0.0-rc3.js 弹出层
qTip2是一个灰常强大且精致的jQuery提示信息插件,是qTip的第2版,也是一个全新的版本,提供了丰富的功能及漂亮的外观,非常易于使用。
提示未功能,包括样式 位置 事件都可以 由自己定义 。。。很强很方便。。
前端项目-qtip2,介绍…第2季度。第二代高级qtip插件,用于流行的jquery框架。
qTip是一个实现圆角对话气泡框样式的Tooltip jQuery插件。支持多种浏览器,可定制,功能强大。
NULL 博文链接:https://hcty31.iteye.com/blog/1187482
提供为 Rails 3.1+ 资产管道打包的qTip2 jQuery 插件。 安装 将这些行添加到应用程序的Gemfile : # qtip2 jquery plugin packaged for the rails asset pipeline gem 'qtip2-jquery-rails' , '~> 2.2.100' 然后...
是qTip2的中文API PDF格式的,可以看看这篇文章http://blog.csdn.net/yhc13429826359/article/details/7796033