0

私は次のようなqtip2ライブラリを使用しています:

$('.selector').qtip({ // options // });

ただし、3つの異なるオプションセットを使用する3つの異なるセレクターがあります。

.qtip部分を関数として記述して、セレクターとオプションを引数として渡す方法はありますか?異なるセレクターの位置を変更しているだけです。変更されているのはそれだけです...

function doMyQtip(selector, "top left", "bottom right") {

}
4

1 に答える 1

1

これを試して:

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);
})

スイッチケースを試すこともできますが、それは少し面倒です。また、JQueryのextend関数(再利用可能なコードを拡張するためのhttp://api.jquery.com/jQuery.extend/ )を確認することもできます。お役に立てれば。

于 2012-01-20T21:01:17.787 に答える