JQuery Draggable and Resizeable over IFrames (Solution)

前端 未结 6 1201
野性不改
野性不改 2021-02-07 02:55

I recently ran into some troubles using JQuery Draggable and Resizable plugins. Looking for solutions, i found some very fragmented code in many different places and finally fil

相关标签:
6条回答
  • 2021-02-07 03:15

    Try this:

     $('#Div').draggable({ iframeFix: true });
    

    This should work.

    0 讨论(0)
  • 2021-02-07 03:18

    I first also went like Byron Cobb's solution, but as I'm using a dialog element and the Iframe isn't needed when the dialog is shown (it's a saving dialog), I liked using the modal option:

    $('#savingDialog').dialog({
        modal: true
    });
    
    0 讨论(0)
  • 2021-02-07 03:26

    Why so hard? There is much more beautiful solution:

    • put your iframe inside relative div with some z-index, say 0
    • make iframe relative also and change it's z-index to -1 during dragging:

    code:

    $("#Div").draggable({
        start: function () {
            $("iframe").css('z-index', '-1');
        },
        stop: function () {
            $("iframe").css('z-index', '0');
        }
    });
    
    0 讨论(0)
  • 2021-02-07 03:29

    All great answers, but none were easily implemented for me!

    I was helped, but in the end, I used:

    Inside the Iframe Header <script> tag:

    var iframes = window.parent.$('iframe');
    iframes.each(function () {
        if ($(this).attr('src') == '<YOUR SOURCE PATH>')
        $(this).css('z-index', '-1');
    });
    

    This is to fix a TinyMCE IFrame Draggable issue. on applying this code inside the iframe, the Non-Draggable problem. Also, check the order of the *.js files, it makes a difference!

    0 讨论(0)
  • 2021-02-07 03:31

    What I've done is define body.dragging iframe {pointer-events: none;} then add dragging class to body on dragstart event and remove it on dragend event.

    Works fine for me, not sure why it wasn't mentioned before, as far as I can tell pointer-events CSS property was already around in 2010.

    0 讨论(0)
  • 2021-02-07 03:34

    There are a number of ways to achieve this, all depending on your needs. I found resizing/dragging many windows slows the UI down a lot, and as such I ended up hiding the iframes on start of resize/Drag with a border to help navigation.

    There are some jquery plugins that achieve part of this functionality, but many struggle with iframes.

    The bring to front can also be improved at points and may not work in all situations.

    0 讨论(0)
提交回复
热议问题