3

リンクの onclick を表示する div があり、マウスが div の外でクリックされたときに非表示にしたい (ほとんどのモーダル ボックス機能と同様) - 問題は、ユーザーがブラウザーのスクロールバーを使用すると、それが a と見なされることです。クリックしてdivを非表示にします

これは、divを表示するために使用するものです

$('.trigger').click(function(e){
    e.preventDefault();
    open_slideout(this);
});

function open_slideout(el){
    $(document).unbind('mousedown');

    //code here to display the div if its not already shown

    //close on click-out
    $(document).bind('mousedown',function(){
        $(panel_id).removeClass('active').hide('fast');
        $(el).removeClass('active');
    });
    $('.panel.active').bind('mousedown',function(e){e.stopPropagation();});
    $('.trigger').bind('mousedown',function(e){e.stopPropagation();});
}

アクティブな領域内をクリックすると stopPropagation を設定しましたが、先ほど言ったように、スクロールバーを使用すると div が非表示になります

4

2 に答える 2

3

これでうまくいったようです:

$(document.body).bind('mousedown',function(){
于 2011-04-21T16:24:17.577 に答える
0
$(window).scroll(function(){
   scrolling = true;
});

/*other code */
$(document).bind('mousedown',function(){
if(!scrolling){
        $(panel_id).removeClass('active').hide('fast');
        $(el).removeClass('active');
}
    }).bind('mouseup',function(){ scrolling = false; })
/*other code */
于 2011-04-20T18:50:48.533 に答える