admin管理员组文章数量:1333450
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.
I have tried this
$('#popupNew').popup({ dismissible: false });
$('#popupNew').popup('open');
But this creates a modal popup that prevents users from interacting with rest of the page.
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.
I have tried this
$('#popupNew').popup({ dismissible: false });
$('#popupNew').popup('open');
But this creates a modal popup that prevents users from interacting with rest of the page.
Share Improve this question edited Jul 23, 2013 at 13:17 kolexinfos asked Jul 23, 2013 at 13:11 kolexinfoskolexinfos 1,0021 gold badge21 silver badges44 bronze badges 1- Check out for JQuery UI lib, they got a good "Dialog" widget for easy build of popup :) ! – Okazari Commented Jul 23, 2013 at 13:19
1 Answer
Reset to default 6Intro
I hope this is everything you need.
- Popup can not be closed if surface outside of it is clicked
- Elements below popup are now accessible
- Popup is draggable (tested on Firefox, Chrome, Android Chrome)
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 is used to make page clickable when popup is opened. Overlay div name is bination of popup id and suffix -screen, in this case it is #popupBasic-screen
.
Working example
Working example: http://jsfiddle/Gajotres/tMpf7/
Code used
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./mobile/1.3.1/jquery.mobile-1.3.1.min.css" />
<!--<script src="http://code.jquery./jquery-1.9.1.min.js"></script>-->
<script src="http://code.jquery./ui/1.10.2/jquery-ui.js"></script>
<script src="http://code.jquery./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 pletely 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;
}
本文标签: javascriptDraggable NonModal Popup Jquery MobileStack Overflow
版权声明:本文标题:javascript - Draggable Non-Modal Popup Jquery Mobile - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742340139a2456434.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论