Replace Div with another Div

前端 未结 3 1382
悲哀的现实
悲哀的现实 2020-11-30 08:29

I have this thing I m trying to do. I have a main picture of a map and within that map there are regions. These regions have hot spots on them so you can click them and it w

3条回答
  •  暗喜
    暗喜 (楼主)
    2020-11-30 09:18

    This should help you

    HTML

    
    
    
    All Regions (shows main map) (link)
    Northern Region (link)
    Southern Region (link)
    Eastern Region (link)

    All Regions image
    northern image
    southern image
    Eastern image

    JavaScript

    var originalmap;
    var flag = false;
    
    $(function (){
    
        $(".replace").click(function(){
                flag = true;
                originalmap = $('#mainmap');
                $('#mainmap').replaceWith($(this));
            });
    
        $('.showall').click(
            function(){
                if(flag == true){
                    $('#region').append($('#mainmapplace .replace'));                
                    $('#mainmapplace').children().remove();
                    $('#mainmapplace').append($(originalmap));
                    //$('#mapplace').append();
                }
            }
        )
    
    })
    

    CSS

    #mainmapplace{
        width: 100px;
        height: 100px;
        background: red;
    }
    
    #region div{
        width: 100px;
        height: 100px;
        background: blue;
        margin: 10px 0 0 0;
    }
    

提交回复
热议问题