jQuery ui dialog dragging issues
Asked Answered
Z

6

22

I used the jQuery ui (jquery-ui-1.10.3) dialog pluggin for one of our products, and found a possible "problem": When the hosting page is small or the current view of the hosting page is scrolled to the top, dragging an openned dialog box behaves as what is expected. The problem start to manifest when hosting a dialog in a large page which is scrolled to somewhere not at the top, in which case the dialog box starts to jump around during dragging. It happens to both IE 9 and the latest Firefox (21.0).

The page is dynamically generaed, complex and has to be long. I am not familiar with fiddle, but it seems to have no option for jQuery-ui lib option that I can use.

More specifically, I found if I scoll the hosting page 100px down (so the top 100px of the hosting page is 'feed' into the top border of the browser window) then when I drag the dialog, instead of it following the mouse, it jumps down 100px so that it is out of the mouse capture.

The dialog is initiallized as

$(element).dialog({ 
    autoOpen: false, width: 950, height: 820, 
    modal: false, resizable: true, draggable: true
});

My questiong is: 1) does any one else has the same issue? 2) If so, is this an setting issue or a bug.

Any expert here can help me with it?

Zeeland answered 22/6, 2013 at 5:4 Comment(8)
Try being way more specific when you describe the issue. You should consider sharing a fiddle that demonstrates what you're experiencig. You can't just say "it starts to jump around" and expect us to understand the issue from a technical perspective. Are you trying to use the containment option? Let's see your code.Locally
The page is dynamically generaed, complex and has to be long. Being not familiar with fiddle, it seems to have no option for jQuery-ui.Zeeland
You can choose from many different versions of jQuery in the dropdown on the left side under "Frameworks and Extensions" (the first thing on the page).Locally
What kind of CSS is involved? That would be the first place I'd look... I would play around with jsFiddle (or other options). As you try to piece together a reproduceable example, you'll probably stumble across the piece of code that's causing it.Locally
Baseically all the jQuery-ui ones, plus jquery.qtip one and our own css. I will look to see if we had bugs in our own css files. But from the behavior shown, it seems to be the lib does not treat/distinguish the window top or document top properly, just a guess, I could be wrong ...Zeeland
My guess is you have some kind of fixed position on a style applied to your draggable div. It's really easy to play around with html, css, and JavaScipt on jsFiddle. The link above also suggests many alternatives that are easy to learn (and actually kinda fun). Also check out Firebug.Locally
Firebug is my default debugger for web pages. I am currently looking into the styles of the draggable and found no fixed position specification at present, I will try to clean the page up to see if the problem persists.Zeeland
Share a live link at least.Indophenol
B
36

I used to have the same issue, content on the page is generated automatically. It is very long.

html, body {position: relative} solves the problem.

Bise answered 1/11, 2013 at 15:29 Comment(4)
I was having the issue with 1.10.4. This fixed it with no observable side effects.Carbarn
Thank you, but this is very strange. I had 1.10.4 and html, body { position: relative } and faced this bug. The bug was resolved after reading this post, I tried to remove position: relative from html and body and the problem was gone.Spitzer
Wow, I'm kinda amazed that worked. The CSS fix resolved my issue in IE8+ and Firefox for jqueryUI 1.10.3 and jquery 1.9.1.Kist
this fixed our issue as well, +1Jenijenica
Z
10

OK, I found this is a bug of jQuery-ui 1.10.3, see here:

That appears only with using UI 1.10.3 and when the scrollbar is not at the very top in Firefox, Opera, IE8.

In Chrome works fine and also with 1.10.2 on other browsers.

The UI dialog demo page has this bug too:

drag the dialog down until appears the scrollbar scroll down again drag the dialog down. dialog goes down with the offset

Zeeland answered 22/6, 2013 at 7:11 Comment(4)
+1, this actually happens on the jquery UI dialog sample page if you introduce a vertical scroller in the container.Georgetta
@Alex, nice catch. A quick solution is to use 1.10.2, if possible.Frodin
I actually had the same problem with 1.10.2 and 1.11.0. This does not happen when you drag the dialog if the underlying page is at top position (vertical scrollbar in top position). However if you scroll down a bit and open the dialog and then try to move it, it will jump down be approx equal length as you've scrolled down the page.Hogen
That is, the dialog seems to be messing up with absolute and relative coordinates of the page.Hogen
C
6

My solution to fix this bug is similar to that of Dado, but using the drag event:

        $(element).dialog({
            draggable: true,
            drag: function(event, ui) {
                var fixPix = $(document).scrollTop();
                iObj = ui.position;
                iObj.top = iObj.top - fixPix;
                $(this).closest(".ui-dialog").css("top", iObj.top + "px");
            }
        });

My version: jQuery UI - v1.10.3 - 2013-10-10

Cacilie answered 8/10, 2014 at 17:23 Comment(1)
I'm using apex 5.0 integrated with jQueryUI 1.10.4 problem is also there your fix repaired this issue.Discommon
K
2

I think there is a bug. I faced to this problem too. My solution for fixing this to turn off the dragging. Just make draggable false. Like this:

$(element).dialog({ 
    autoOpen: false, width: 950, height: 820, 
    modal: false, resizable: true, draggable: false
});
Kulsrud answered 19/9, 2013 at 4:19 Comment(0)
L
1

Update the jQuery UI Library (js) worked for me. http://jqueryui.com/download/
Remember to update your css files too.

Liverpool answered 8/8, 2014 at 20:9 Comment(0)
R
0

Bugreport: view bug report

My solution to fix this bug is to "reset" the "ui.position.top" (for me 228px).

$(element).dialog({
    dragStart: function(event, ui) {
        var fixPix = 228; // offset top (add your own here!)
        iObj = ui.position;
        if (iObj.top > fixPix) {
            iObj.top = iObj.top - fixPix;
        }
        ui.position = iObj;
    }
});

My version: jQuery UI - v1.10.4 - 2014-01-17

This solution works for me. Hope it helps you too until this ugly bug is fixed.

Richel answered 27/6, 2014 at 16:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.