可移植非模态弹出Jquery Mobile [英] Draggable Non-Modal Popup Jquery Mobile

查看:134
本文介绍了可移植非模态弹出Jquery Mobile的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Jquery mobile中有一个弹出式窗口,不会阻止用户与页面交互,而data-dismissible =false,即当页面的另一部分与页面交互并保持可见时弹出窗口不会消失。

I want to have a popup in Jquery mobile that would not stop users from interacting with a page and data-dismissible="false" that is the popup would not disappear when another part of the page is interacted with and stays visible.

我试过了这个

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

但这会创建一个模式弹出窗口,阻止用户与页面的其余部分交互。

But this creates a modal popup that prevents users from interacting with rest of the page.

推荐答案

简介



我希望这是你需要的一切。

Intro

I hope this is everything you need.


  • 弹出式窗口在其外部被点击时无法关闭

  • 现在可以访问弹出式窗口下面的元素

  • 弹出菜单是可拖动的(在Firefox,Chrome和Android Chrome上测试)

这里使用的一些JavaScript代码不是我的,我说的是一个修复程序,使它可以在移动设备上拖动。很遗憾,我不记得自己的解决方案了。

Few more notes. Some of a javascript code used here is not mine, I am talking about a fix used to make it draggable on mobile devices. Unfortunately I can't remember whose solution it is.

CSS用于在弹出窗口打开时使页面可点击。重叠div名称是弹出式ID和后缀-screen的组合,在这种情况下,它是 #popupBasic-screen

CSS is used to make page clickable when popup is opened. Overlay div name is combination of popup id and suffix -screen, in this case it is #popupBasic-screen.

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

<!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:



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:



CSS:

#popupBasic-screen {
    display: none;
}

这篇关于可移植非模态弹出Jquery Mobile的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆