0

モデルビューを使って小さなフォトギャラリーを作ろうとしています。しかし、写真をクリックすると、モデルビューが開いて写真が表示されますが、フォトギャラリーからも削除されます。appendを使用してモデルにvievユーザー情報を作成しました。

 <div class="userList">
<div class="user" href="#?w=500" rel="popup_name"> <img src="style/images/category/1.jpg" /></div>
<div class="user" href="#?w=500" rel="popup_name"> <img src="style/images/category/2.jpg" /></div>
<div class="user" href="#?w=500" rel="popup_name"> <img src="style/images/category/3.jpg" /></div>
</div>

<div id="popup_name" class="popup_block">

    <div id="userPhoto"></div>
    <div id="description"></div>
</div>

これは私の.jsファイルです

  $(document).ready(function(){

    $(".userList").children().each(function(idy) {


        var $this =$(this);


    $(this).hover(function () {
            var $this   = $(this);
                $this.stop().animate({'opacity':'1.0'},200);
            },function () {
            var $this   = $(this);
                $this.stop().animate({'opacity':'0.4'},200);
        }).bind('click',function(){


             var $theImage   = $(this);

        var popID = $(this).attr('rel'); 
        var popURL = $(this).attr('href'); 


        var query= popURL.split('?');
        var dim= query[1].split('&');
        var popWidth = dim[0].split('=')[1]; 

        //Fade in the Popup and add close button
        $('#' + popID).fadeIn().css({ 'width': Number( popWidth ) }).prepend('<a href="#" class="close"><img src="style/images/logo.png" class="btn_close" title="Close Window" alt="Close" /></a>');


    $('#popup_name').append($theImage);


        var popMargTop = ($('#' + popID).height() + 80) / 2;
        var popMargLeft = ($('#' + popID).width() + 80) / 2;


        $('#' + popID).css({
            'margin-top' : -popMargTop,
            'margin-left' : -popMargLeft
        });


        $('body').append('<div id="fade"></div>');
        $('#fade').css({'filter' : 'alpha(opacity=80)'}).fadeIn();

        return false;
    });
    });

     $('#popup_name > img').live('click',function(){
                $this = $(this);
                $('#description').empty().hide();


                   $this.remove();

            });


    $('a.close, #fade').live('click', function() {
        $('#fade , .popup_block').fadeOut(function() {
            $('#fade, a.close').remove(); 

        });
        return false;
    });


    });
4

1 に答える 1

0

あなたの状況で電話.append()をかけると、実際に画像が移動します。これは、次のように表示されます。

$('#popup_name').append($theImage);

代わりに、コピーを追加したいので、次のように、.clone()または.clone(true)ここを使用します(イベントハンドラーがバインドされているため)。

$('#popup_name').append($theImage.clone());

コピーでその呼び出しからの動作が必要な場合は、を使用しますが、ここではそれを望まないと思います。.hover()#popup_name.clone(true)

于 2010-09-15T15:11:53.783 に答える