[英]Qtip2: write as function (and pass different selectors as an argument)
I am using the qtip2 library which looks like this: 我正在使用看起来像这样的qtip2库:
$('.selector').qtip({ // options // });
However I have three different selectors which use three different set of options. 但是,我有三个不同的选择器,它们使用三个不同的选项集。
Is there a way to write the .qtip part as a function so I can pass the selector, and the options as arguments? 有没有一种方法可以将.qtip部分编写为函数,以便我可以将选择器和选项作为参数传递? I am just changing the position for different selectors, that's the only thing that is changing...
我只是在更改不同选择器的位置,这是唯一正在更改的内容...
function doMyQtip(selector, "top left", "bottom right") {
}
Try this: 尝试这个:
function changeQtipVars(pos1, pos2){
var tooltip_opts = {
position: {
corner: {
target: pos1,
tooltip: pos2
}
}
}
return tooltip_opts;
}
$('.selector').qtip({
content: 'Displays the number of results based on your search criteria.',
show: 'mouseover',
hide: 'mouseout',
style: changeQtipVars(pos1, pos2);
})
You can also try a switch case, but that works out to be a tad tedious. 您也可以尝试使用开关盒,但这确实有些繁琐。 You may also want to read up on JQuery's extend function - http://api.jquery.com/jQuery.extend/ for extending reusable code.
您可能还需要阅读JQuery的扩展功能-http: //api.jquery.com/jQuery.extend/以扩展可重用的代码。 Hope this helps.
希望这可以帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.