show/hide jQuery dialog box on mouseover

后端 未结 3 2069
隐瞒了意图╮
隐瞒了意图╮ 2021-01-13 12:39

I\'m trying to make a mouseover map area on an image that must display a dialog box when the mouse is over. The dialog box content is different, depending on which area it i

3条回答
  •  长情又很酷
    2021-01-13 13:16

    Assign the box dialog to a variable and then don't queue more jquery events with it because it will break your code.

    Since Ids need always to be unique we need to do some changes in your html and css

    ids: #box0, #box1

    class: .box

    $(function() {
             $('.box').each(function(k,v){ // Go through all Divs with .box class 
                   var box = $(this).dialog({ modal:true, resizable:false,autoOpen: false });
                        $(this).parent().find('.ui-dialog-titlebar-close').hide();
    
                     $( "#elem"+k ).mouseover(function() { // k = key from the each loop
                        box.dialog( "open" );
                        }).mouseout(function() {
                        box.dialog( "close" );
                    });
              });
        });
    

    working example: jsfiddle

提交回复
热议问题