質問

私がやろうとしていること:

ユーザーが画像の上にhotingしたら、右上隅に小さなx(画像)が表示されるはずです。ユーザーがこの小さなXをクリックすると、画像を削除する必要があり、ユーザーがマウスアウトを行うと、小さなXが消えてしまうはずです。私はいくつかのことを試しました:

HTML構造は、liとその中に画像を備えたULです

JavaScript:

//On all the li's in the ul

$("li",$flickrKeyUlPreview).mouseover(addExternalImage);

var addExternalImage = function(){

        //Get the offset of the image the user is hovering over
        var offset = $(this).offset();

        //Move the little x button to the image
        $flickrDetailButton.offset(offset);

        //Set it visible
        $flickrDetailButton.css("visibility","visible");

        //Bind the event for the mouseout
        $flickrDetailButton.mouseout(removeExternalButton);
};

var removeExternalButton = function(){

        //Hide the little x
        $flickrDetailButton.css("visibility","hidden");
};

これがうまくいかない理由:ユーザーが小さな画像の上に浮かぶとき、マウスオーバーがトリガーされます。

私も試しました:

$("li",$flickrKeyUlPreview).mouseover(addExternalImage);

     var addExternalImage = function(){
        $(this).unbind('mouseover');
        var emptyObject = {};
        $(this).append($.TemplateRenderer($flickrDetailButton,emptyObject));
        $flickrDetailButton = $('#flickr_detail_button',rootel);
        $(this).mouseout(removeExternalButton);
    };


   var removeExternalButton = function(){
        $(this).unbind('mouseout');
        $flickrDetailButton = $('#flickr_detail_button',rootel);
        if ($($flickrDetailButton, $(this))) {
            $($flickrDetailButton, $(this)).remove();
        }
        $(this).mouseover(addDelBtn);
    };

This doesn't work that well, the little x starts flickering.

これも試しました:

$("li",$flickrKeyUlPreview).mouseenter(addExternalImage);

    var removeExternalButton = function(){
        $flickrDetailButton = $('#flickr_detail_button', rootel);
        if ($($flickrDetailButton, $(this))) {
            $($flickrDetailButton, $(this)).remove();
        }
        $(this).mouseenter(addExternalImage);
    };


    var addExternalImage = function(){
        var emptyObject = {};
        $(this).append($.TemplateRenderer($flickrDetailButtonTemplate,emptyObject));
        $flickrDetailButton = $('#flickr_detail_button',rootel);
        $(this).mouseout(removeExternalButton);
        $flickrDetailButton.mouseleave(removeExternalButton);
    };

これは同じ効果を与えました、それはまだちらつきました

誰かがこれを行う方法を別のアイデアを持っていますか(特定のコードを必要としない、概念も高く評価されています;))?

役に立ちましたか?

解決

$( 'selector')。Hover(addexternalimage、removeExternalButton);

他のヒント

交換 mouseovermouseoutmouseentermouseleave.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top