Broken jQuery Accordion in Google Maps

左心房为你撑大大i 提交于 2019-12-25 13:19:14

问题


I am trying to display a jQuery accordion inside of a Google Map, I have it working however when I click away from my accordion menu it will not act as an accordion when I re-open it. I'm at a loss as to how to fix it without creating my own accordion from scratch. Any help as to how to make it work properly?

http://mulibraries.missouri.edu/Reference/virtour/demo_fs_mobile.php


回答1:


You need create these elements again with events too.

I improved your code using jQuery, try this:

function HomeControl(controlDiv, map) {
    var menu_btn = $("<div>");
    menu_btn.attr('id', 'menu_btn');
    menu_btn.attr('title', 'Click to show the Map Navigation');
    menu_btn.html('<b>Menu</b>');
    menu_btn.css({
        backgroundColor: 'white',
        cursor: 'pointer',
        textAlign: 'center',
    });

    $(menu_btn).click(function() {
        $(controlDiv).empty();

        menu_state = 1;

        var menu_nav = $("<div>");
        menu_nav.attr('id', 'menu_nav');
        menu_nav.attr('title', 'Click Map to close Menu');
        menu_nav.css({
            backgroundColor: 'white',
            cursor: 'pointer',
            textAlign: 'center',
        });

        var accordion = $('<div id="accordion"><h3><a href="#">Change Library</a></h3> <div>Ellis<br>Engineering<br>Journalism</div><h3><a href="#">Change Floor</a></h3> <div>Ground Floor<br>First Floor<br>Second Floor<br>Third Floor<br>Fourth Floor<br></div> <h3><a href="#">Change Map</a></h3> <div>Virtual Tour<br>Video Tour<br>Study Rooms<br>Computers</div></div>');

        $(menu_nav).append(accordion);
        $(controlDiv).append(menu_nav);

        $(accordion).accordion({active: 1, autoHeight: false});
    });

    $(controlDiv).empty();
    $(controlDiv).append($(menu_btn).clone(true));

    google.maps.event.addDomListener(map, 'click', function() {
        menu_state = 0;

        $(controlDiv).empty();
        $(controlDiv).append($(menu_btn).clone(true));
    });
}

Hope this helps.



来源:https://stackoverflow.com/questions/12729793/broken-jquery-accordion-in-google-maps

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!