簡體   English   中英

可拖動的非模式彈出式jQuery Mobile

[英]Draggable Non-Modal Popup Jquery Mobile

我想在Jquery mobile中創建一個彈出窗口,該彈出窗口不會阻止用戶與頁面進行交互,而data-dismissible =“ false”就是當頁面的另一部分與之交互並保持可見時,彈出窗口不會消失。

我已經試過了

 $('#popupNew').popup({ dismissible: false });
 $('#popupNew').popup('open');

但這會創建一個模式彈出窗口,以防止用戶與頁面的其余部分進行交互。

介紹

我希望這就是您需要的一切。

  • 如果單擊彈出窗口的外部表面,則無法將其關閉
  • 現在可以訪問彈出框下方的元素
  • 彈出窗口可拖動(已在Firefox,Chrome,Android Chrome上測試)

幾個筆記。 這里使用的一些javascript代碼不是我的,我說的是用於使其可在移動設備上拖動的修復程序。 不幸的是,我不記得是誰的解決方案。

CSS用於在打開彈出窗口時使頁面可單擊。 重疊div名稱是彈出窗口ID和后綴#popupBasic-screen組合,在本例中為#popupBasic-screen

工作實例

工作示例: http : //jsfiddle.net/Gajotres/tMpf7/

使用的代碼

HTML:

<!DOCTYPE html>
<html>
    <head>
        <title>jQM Complex Demo</title>
        <meta http-equiv='Content-Type' content='text/html; charset=utf-8'/>
        <meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; minimum-scale=1.0; user-scalable=no; target-densityDpi=device-dpi"/>
        <link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.1/jquery.mobile-1.3.1.min.css" />
        <!--<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>-->
        <script src="http://code.jquery.com/ui/1.10.2/jquery-ui.js"></script>              
        <script src="http://code.jquery.com/mobile/1.3.1/jquery.mobile-1.3.1.min.js"></script>    
    </head>
    <body>
        <div data-role="page" id="index">
            <div data-theme="b" data-role="header">
                <h1>Index page</h1>
            </div>

            <div data-role="content">
                <a href="#popupBasic" data-rel="popup" data-role="button" data-inline="true" data-transition="pop" >Basic Popup</a>
                <a data-role="button" id="test">click me</a>                
                <div data-role="popup" id="popupBasic" data-dismissible="false">
                    <a href="#" data-rel="back" data-role="button" data-theme="a" data-icon="delete" data-iconpos="notext" class="ui-btn-right">Close</a>
                    <p>This is a completely basic popup, no options set.</p>
                </div>
            </div>
        </div>    
    </body>
</html>   

Javascript:

$(document).on('pagebeforeshow', '#index', function(){ 
    $('#popupBasic').draggable({
        cursor: 'move'
    });
    $(document).on('click', '#test', function(){ 
        alert('Successful click!');
    });
});

// This is a fix for mobile devices,, rest of the code is not mine

/iPad|iPhone|Android/.test( navigator.userAgent ) && (function( $ ) {

var proto =  $.ui.mouse.prototype,
_mouseInit = proto._mouseInit;

$.extend( proto, {
    _mouseInit: function() {
        this.element
        .bind( "touchstart." + this.widgetName, $.proxy( this, "_touchStart" ) );
        _mouseInit.apply( this, arguments );
    },

    _touchStart: function( event ) {
         this.element
        .bind( "touchmove." + this.widgetName, $.proxy( this, "_touchMove" ) )
        .bind( "touchend." + this.widgetName, $.proxy( this, "_touchEnd" ) );

        this._modifyEvent( event );

        $( document ).trigger($.Event("mouseup")); //reset mouseHandled flag in ui.mouse
        this._mouseDown( event );

        //return false;           
    },

    _touchMove: function( event ) {
        this._modifyEvent( event );
        this._mouseMove( event );   
    },

    _touchEnd: function( event ) {
        this.element
        .unbind( "touchmove." + this.widgetName )
        .unbind( "touchend." + this.widgetName );
        this._mouseUp( event ); 
    },

    _modifyEvent: function( event ) {
        event.which = 1;
        var target = event.originalEvent.targetTouches[0];
        event.pageX = target.clientX;
        event.pageY = target.clientY;
    }

});

})( jQuery );

CSS:

#popupBasic-screen {
    display: none;
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM