1

プラグインには次のものがあります。

var defaults = {
    hide: function ($element, $tooltip) {
        $tooltip.fadeOut(4000);
    }
};
$(this).each(function (e) {
    $this.mouseleave(function (e) {
        tooltip.timer = setTimeout(function () {
            options.hide($this, $("." + options.class).stop(true, true), function () {
                $("." + options.class).remove(); // THE ELEMENT IS NOT BEING REMOVED
            });
        }, 0);
    }), // Mouse leave  
})

マウスを離すと、アニメーションが終了した後に要素を削除しようとしています。

問題は、要素が削除されていないことです。しかし、次を使用すると機能します。

$this.mouseleave(function (e) {
    tooltip.timer = setTimeout(function () {
        options.hide($this, $("." + options.class).stop(true, true));
        $("." + options.class).remove(); // THE ELEMENT IS BEING REMOVED
    }, 0);
}), // Mouse leave

その後、すべて正常に動作します... function() { ... } が削除アクションを無効にするのはなぜですか?

4

2 に答える 2

1

そのように 3 番目のパラメーター (コールバック) を渡すことはできません。これを試して:

var defaults = {
    hide: function ($element, $tooltip, $func) {
        if(typeof $func === 'function');
            $tooltip.fadeOut(4000, 'swing', $func);
        else
            $tooltip.fadeOut(4000);
    }
};

$(this).each(function (e) {
    $this.mouseleave(function (e) {
        tooltip.timer = setTimeout(function () {
            options.hide($this, $("." + options.class).stop(true, true), function () {
                $("." + options.class).remove(); // THE ELEMENT IS NOT BEING REMOVED
            });
        }, 0);
    }), // Mouse leave  
})

編集:

JSFiddle のデモ: http://jsfiddle.net/wcX3g/

于 2013-04-23T21:11:47.260 に答える
0

私はあなたが別thisの を参照していると思います.1つは$(this)これまでどの要素も参照していません.そして、$this内部$(this).each()には $(this) は誰ですか???, $('.クラス名')。次に、内部で同じ className を持つ各要素に $(this) を使用できます。

$('.myClass').each(function (e) {
    $(this).mouseleave(function (e) {
        tooltip.timer = setTimeout(function () {
            options.hide($this, $("." + options.class).stop(true, true), function () {
                $("." + options.class).remove(); 
            });
        }, 0);
    }),  
})

多分あなたはJquery hoverを使うことができます:

$(this).hover(function(){
    //on mouse over
}, function(){
    //on mouse out
    $(the_elm_toRemove).remove();
});
于 2013-04-23T21:14:50.680 に答える