作者在 2023-07-13 23:35:43 发布以下内容
在 layer.js 文件最下面加上补丁代码:
(function () {
old_layer_tips = layer.tips
layer.tips = function(content, follow, options) {
old_success = options['success'] || function (the_tips, index) {}
options['success'] = function(the_tips, index) {
if ('offset' in options) {
var oldTop = parseFloat(the_tips.css("top").replace('px', ''));
var oldLeft = parseFloat(the_tips.css("left").replace('px', ''));
var offset = options['offset']
var offsetTop = parseFloat(String(offset[0]).replace('px', ''));
var offsetLeft = parseFloat(String(offset[1]).replace('px', ''));
the_tips.css({
top: `${oldTop + offsetTop}px`,
left: `${oldLeft + offsetLeft}px`
})
}
old_success(the_tips, index)
}
return old_layer_tips(content, follow, options)
}
})(layer)
调用示例:layer.tips('显示在目标元素上方', '#id', {
tips: 1,
offset: ['-50px', '100px']
});