javascript - Jquery 移动弹出窗口上方/带有谷歌地图

标签 javascript jquery jquery-mobile google-maps-api-3 jquery-mobile-popup

使用 jQuery Mobile,我无法加载加载谷歌地图的弹出窗口。 如果我触摸 id="popupBasic"则不会弹出任何内容。很奇怪,但是如果谷歌地图 api 没有加载,弹出窗口就可以工作!

>

 <html>

<head>

    <meta name="viewport" content="width=device-width, minimum-scale=1, maximum-scale=1">

    <meta http-equiv="Content-type" content="text/html; charset=utf-8">
    <title>Beer Me</title>
    <link rel="stylesheet" href="css/jquery.mobile-1.3.1.css" />
    <link rel="stylesheet" href="css/jquery.mobile.structure-1.3.1.css" />
    <link rel="stylesheet" href="css/datepicker.css" />
    <script type="text/javascript" charset="utf-8" src="cordova.js"></script>
    <script type="text/javascript" src="js/jquery.js"></script>
    <script type="text/javascript" src="js/jquery.mobile-1.3.1.js"></script>
    <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
    <script type="text/javascript" charset="utf-8" src="js/map.js"></script>
    <script type="text/javascript" charset="utf-8" src="markers.js"></script>
    <script>

        $.mobile.page.prototype.options.domCache = true ;
        $.mobile.allowCrossDomainPages = true;
        $(document).on('pageshow', '#map', function (event)
        {
            max_height();
            $(document).on('click', '#myposition', function (event){
                navigator.geolocation.getCurrentPosition(onSuccess, onError,{'enableHighAccuracy':true,'timeout':20000});
            });
        });

    </script>
    <script type="text/javascript" charset="utf-8" src="js/datepicker.js"></script>
    <script type="text/javascript" charset="utf-8" src="js/datepicker.mobile.js"></script>
</head>
<body onload="onLoad()">
<div data-role="page" id="map">
   <div data-role="header" data-theme="b">
        <a href="index.html" data-icon="grid" rel="external">Menu</a>
        <h1>Map Header</h1></div>
    <div data-role="content" style="width:100%; height:100%; padding:0;">
        <div data-role="popup" id="popupBasic">
            <p>This is a completely basic popup, no options set.<p>
        </div>
        <div id="map_canvas" style="width:100%;height:100%"></div>
    </div>
    <div data-role="footer" data-theme="b" data-position="fixed">
        <div data-role="navbar">
            <ul>
                <li><a href="#leftpanel" data-role="button" data-inline="true"   data-icon="grid" >Date</a></li>
                <li><a href="#" data-icon="star" id="testbtn">Favs</a></li>
                <li><a href="#" data-icon="gear" id="myposition">My position</a></li>
                <li><a href="#popupBasic" data-rel="popup">Open Popup</a></li>
            </ul>
        </div><!-- /navbar -->
    </div>
</div>
</body>
</html>

有人有同样的问题吗?我想不通..

问候,

弗兰克

最佳答案

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

我更改了您的示例,如果您单击按钮#myposition,则会显示弹出窗口。

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"/>
        <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=true"></script>          
        <link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.1/jquery.mobile-1.3.1.min.css" />
        <script>
            $(document).bind("mobileinit", function(){
                $.mobile.page.prototype.options.domCache = true ;
                $.mobile.allowCrossDomainPages = true;
            });
        </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="map">
            <div data-role="header" data-theme="b">
                <a href="index.html" data-icon="grid" rel="external">Menu</a>
                <h1>Map Header</h1>
            </div>
            <div data-role="content" style="width:100%; height:100%; padding:0;">
                <div data-role="popup" id="popupBasic">
                    <p> This is popup</p>
                </div>
                <div id="map_canvas" style="width:100%;height:100%"></div>                 
            </div>
            <div data-role="footer" data-theme="b" data-position="fixed">
                <div data-role="navbar">
                    <ul>
                        <li>
                            <a href="#leftpanel" data-role="button" data-inline="true"   data-icon="grid" >Date</a>
                        </li>
                        <li>
                            <a href="#" data-icon="star" id="testbtn">Favs</a>
                        </li>
                        <li>
                            <a href="#" data-icon="gear" id="myposition">My position</a>
                        </li>
                        <li>
                            <a href="#popupBasic" data-rel="popup" id="openPopup">Open Popup</a>
                        </li>
                    </ul>
                </div>
                <!-- /navbar -->
            </div>
        </div>     
    </body>
</html>     

CSS:

#popupBasic {
    width: 300px !important;
    height: 300px !important;    
}

Javascript:

$(document).on('pageshow', '#map', function (event) {
    max_height();
    $(document).on('click', '#myposition', function (event){
        navigator.geolocation.getCurrentPosition(onSuccess, onError,{'enableHighAccuracy':true,'timeout':20000});
    });
});

function max_height() {
    var header = $.mobile.activePage.find("div[data-role='header']:visible");
    var footer = $.mobile.activePage.find("div[data-role='footer']:visible");
    var content = $.mobile.activePage.find("div[data-role='content']:visible:visible");
    var viewport_height = $(window).height();

    var content_height = viewport_height - header.outerHeight() - footer.outerHeight();
    if((content.outerHeight() - header.outerHeight() - footer.outerHeight()) <= viewport_height) {
        content_height -= (content.outerHeight() - content.height());
    } 
    $.mobile.activePage.find('[data-role="content"]').height(content_height);
}


function onSuccess(position) {       
    var minZoomLevel = 15;

    var map = new google.maps.Map(document.getElementById('map_canvas'), {
        zoom: minZoomLevel,
        center: new google.maps.LatLng(position.coords.latitude, position.coords.longitude),
        mapTypeId: google.maps.MapTypeId.ROADMAP
    });    
}

function onError() {
    alert('Error');
}

关于javascript - Jquery 移动弹出窗口上方/带有谷歌地图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16566863/

相关文章:

javascript - 正确的 jQuery 图像加载()?

android - 如何处理 HTML5 Web 应用程序中的旋转?

javascript - 在 jquerymobile 页面中动态添加元素

JavaScript 自动 POST 和 NAME

jquery - 提升缩放调整缩放窗口以适应不同尺寸的图像

javascript - jQuery - 反向操作

javascript - SVG 元素中的 HTML5 Canvas 与 jQuery

jquery - 点击显示的按钮会触发后台隐藏的按钮事件

javascript - 未集中注意力时更新团队自定义选项卡

javascript - 使用 Jekyll、react 和 webpack 实例化对象的问题