qtip2采用了mit/gplv2许可,官方网站为:https://craigsworks.com/projects/qtip2/,目前还没发布一个稳定版,nightly版本经常会更新,当然这并不影响正常使用。
简介
若不放心可以尝试旧版的qtip,但在一些参数上会有所不同;若是从qtip升级到qtip2,可以使用官方提供的转换工具来升级你的代码:https://craigsworks.com/projects/qtip2/converter/。
如果使用时出现问题,那么直接下载以下3个文件吧,至少官方演示很正常:
代码如下:
<link href="https://craigsworks.com/projects/qtip2/packages/latest/jquery.qtip.min.css" rel="stylesheet" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script src="https://craigsworks.com/projects/qtip2/packages/latest/jquery.qtip.min.js"></script>
除了以上插件的功能外,它的主要功能有(仅列出较常用的):
使用方法
以下就简单演示一些使用方法
创建一个最简单的提示:
. 代码如下:
$("#demo2").qtip({
content: "这是提示内容(by囧月)"
});
. 代码如下:
$("#demo3").qtip({
content: {
text: "这是提示内容(by囧月 lwme.cnblogs.com)"
, title: "提示标题"
}
});
. 代码如下:
$("#demo3").qtip({
content: {
text: "这是提示内容(by囧月 lwme.cnblogs.com)"
, title: {
text: "提示标题"
, button: "关闭"
}
}
});
. 代码如下:
$("a[title]").qtip(); //从链接的title
$("img[alt]").qtip(); //从img的alt
$("p[title]").qtip(); //从p的title
. 代码如下:
$('img[alt]').qtip({
content: {
attr: 'alt'
}
});
. 代码如下:
$("#demo4").qtip({
content: {
text: "加载中...",
ajax: {
url: "lwmeatcnblogs.x?name=囧月"
}
}
});
. 代码如下:
$("#demo5").qtip({
position: {
my: 'bottom left',
at: 'top center'
},
style: {
classes: 'ui-tooltip-red'
}
});
. 代码如下:
$('button').qtip({
content: "这是提示内容(by囧月 lwme.cnblogs.com)",
show: {
event: 'click', // show it on click...
solo: true, // ...and hide all other tooltips...
modal: true // ...and make it modal
},
hide: false
});
. 代码如下:
$('button').qtip({
content: "这是提示内容(by囧月 lwme.cnblogs.com)",
show: {
ready: true
},
hide: false
});
. 代码如下:
$.fn.qtip.defaults = {
// 页面加载完成就创建提示信息的元素
prerender: false,
// 为提示信息设置id,如设置为mytooltip
// 就可以通过ui-tooltip-mytooltip访问这个提示信息
id: false,
// 每次显示提示都删除上一次的提示
overwrite: true,
// 通过元素属性创建提示
// 如a[title],把原有的title重命名为oldtitle
suppress: true,
// 内容相关的设置
content: {
// 提示信息的内容
// 如果只设置内容可以直接 content: "提示信息"
// 而不需要 content: { text: { "提示信息" } }
text: true,
// 提示信息使用的元素属性
attr: 'title',
// ajax插件
ajax: false,
title: {
// 提示信息的标题
// 如果只设置标题可以直接 title: "标题"
text: false,
// 提示信息的关闭按钮
// 如button:"x",button:"关闭"
// 都可以启用关闭按钮
button: false
}
},
// 位置相关的设置
position: {
// 提示信息的位置
// 如提示的目标元素的右下角(at属性)
// 对应 提示信息的左上角(my属性)
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,
// 事件名称,默认为鼠标移到时
// 可以改为click点击
event: 'mouseenter',
// 特效
effect: true,
// 延迟显示时间
delay: 90,
// 隐藏其他提示
solo: false,
// 在页面加载完就显示提示
ready: false,
modal: {
// 启用模态对话框效果
on: false,
// 特效
effect: true,
blur: true,
escape: true
}
},
// 隐藏提示的相关设置
// 参考show
hide: {
target: false,
event: 'mouseleave',
effect: true,
delay: 0,
// 设置为true时,不会隐藏
fixed: false,
inactive: false,
leave: 'window',
distance: false
},
// 样式相关
style: {
// 样式名称
classes: '',
widget: false,
width: false,
height: false,
// tip插件,箭头相关设置
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
}
};
. 代码如下:
$.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'
};
. 代码如下:
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'
]
. 代码如下:
['red', 'blue', 'dark', 'light', 'green','jtools', 'plain', 'youtube', 'cluetip', 'tipsy', 'tipped']
. 代码如下:
$("#demo2").qtip({
content: "这是提示内容(by囧月)"
, style: {
classes: 'ui-tooltip-red ui-tooltip-shadow ui-tooltip-rounded'
}
});
. 代码如下:
$('.selector').qtip({
content: {
text: 'loading...', // loading text...
ajax: {
url: '/path/to/file', // url to the json script
type: 'get', // post or get
data: { id: 3 }, // data to pass along with your request
datatype: 'json', // tell it we're retrieving json
success: function(data, status) {
//...
}
}
}
});
如对本文有疑问, 点击进行留言回复!!
offset、client、scroll (width,height、left,top、X,Y)
网友评论