TeamSpace
Quality vs. quantity Microphone
Home Who We Are What We Do What We've Done Why Work For Us Blog Contact Us

Using jQuery resizable and draggable with fixed position pop up

Monica Mora - October 22 2013 01:45:00 PM


For our purposes, we needed a pop-up that would stay in the viewable section of a web page and allowed the user to move and resize it using jQuery.

Now at this point, most of you are thinking, just use a jQuery dialog right? That's what I thought too! Draggable and resizable are built in....don't reinvent the wheel, use what's there right? So, I build the pop-ups using dialogues, and set obj.draggable () and obj.resizable(). Simple right? One would think so....

Under "normal" conditions this would be the case, set the two properties and move on to the next set of code.

So I set the dialogue to draggable, and life is good. The user can move the dialogue all over the viewable section of the page and all is not lost if the user scrolls.

Now, I add resizable property and test resizing the dialog on initial load of the page, and it works  beautifully.

I move on to the next scrollable section to test another dialog call and here's where it breaks. The dialog loads fine, drags fine, but upon resize, the dialog disappears. Wonderful. I look at the calls, compare the dialog functions verify everything is using the correct calls, etc.

After many hours of combing through function calls, checking firebug for errors, console log statements and yes, even alerts, I've come to the conclusion that there are no errors and no differences in code.

I move to the top of the page, it works. I scroll the page, it disappears.  So at this point, I do what all good developers do, I use a different function. If the jQuery dialog won't conform to my needs, I'll write my own pop-up!

So, here we go, rewriting every "dialog" call...using a fixed position div and visibility. Of course, I test the new pop-up with simple styles and no resizable or draggable properties. Everything works similarly to the dialog. Great!

Now, I think, let's add the draggable, and viola....perfect!

Last test. At this point, I'm confident all will work as I want it to. I'm feeling maybe a touch superior,  I've bent this code to my will! I am the developer king! I can do anything!

Then, I add the draggable and what do you think happens? Of course, same behavior as the dialog. Are you kidding me?? Seriously!!!???

At this point, I do what all good developers do and  I refrain from throwing my computer out the window and walk away. I clean the house, do some laundry, cook dinner and stew over the fact that this code SHOULD work.

I'm thinking what could be breaking it. What on earth could "resizable" be doing that is so finicky??

Then it hits me. BAM. I go back to the computer and check my theory.

I scroll to the middle of the page, activate the pop-up, drag it and then resize it. At this point, I scroll BACK TO THE TOP of the page, and what to my wondering eyes appear? There it is, my resized pop-up sitting at the top of the page.

Of course!  Nothing I do ever fits the mold of "normal".  In this case, we have a long scrolling page with distinct "sections" the user can navigate to via a set of navigation buttons. This being the case, the pop-ups needed to be set to a "fixed" position, thus keeping the pop up in view should the user decide to scroll the page behind it.

jQuery resizable is smart enough to reset the position of my pop-up for me. Why thank you jQuery, your so kind...and NOT cool!

Yes, what happened was my beautifully styled, FIXED position div has been hijacked!!! jQuery has now set my position to absolute with exact left/top positions.

Curse you jQuery! And your little dog too!!!

The obvious solution here, or so it seems, is to simply add a "!important" to the fixed position css style definition.  Typically, "!important" would , in fact, solve this issue, given that the top and left definitions were non-changing and the page wasn't long enough to scroll. While this provided partial relief, my needs were a little more complicated than that of a "normal" page, and this lone solution left me with a "jumpy", erratic and unpredictable behavior, not the smooth resize one might expect.

After a few more hours, I decide to set the position to fixed, and  set the top and left position in the javascript.  This seems like a simple solution that would come to any developer and again, I'm confident.

Upon testing, not so much. Again, hacked by jQuery! Curses! How can I get my calls to sit "below" their calls...and not make the pop-up look "jumpy"....????

Now, I've resorted to google...and it seems I'm not alone. I'm not the only person that has ever needed to set a fixed position pop-up to be resizable.

In combing through many posts...the answers are redundant. They all say "jQuery resizable does not support fixed positioning". WHAAAAAAAT??? Seriously???

In the end, I found a few solutions posted that suggest resetting the position to fixed post resizing. Well I've already tried this.

It finally hits me. I need to set the position to fixed DURING the event, not after! Viola...Success, I feel like Julie Andrews in "The Sound Of Music"! It works. It doesn't jump. It doesn't "move". It does exactly what I want it to do!

So now, for those of you that are less "visual" than I, here is the actual code solution:

First, 2 functions that will resize my iFrame and container:

function resizeURLBox(){
  //size outer box to window
  var uBox=$('#urlBox')
  var divWidth = Math.min($(window).width() - 25, 1000);
  uBox.height(($(window).height() - 130) + 'px');
  uBox.width(divWidth + 'px')
}

function resizeURLFrame(){
  //size inner frame to outer box
  var uFrame = $('#urlFrame');
  uFrame.height(($('#urlBox').height() - 28) + 'px');
  uFrame.width($('#urlBox').width()-2 + 'px');
}


Then, during the pop-up call, in the 'draggable' parameters I added the fixed position to the start event:  

var uBox=$('#urlBox')
  uBox.draggable({handle:'#urlDrag', scroll: false});
  uBox.resizable({
          handles: 'n,s,e,w,ne,se,nw,sw',
          start: function(e, ui) {
          uBox.css('position', 'fixed')
          uBox.css('top', (60)+'px');
          $(window).off('resize', resizeURLBox);  //cancel window resize event s
          $(window).off('resize', resizeURLFrame);
          var d = $("<div class='iframeCover' style='zindex:99;position:absolute;width:100%;top:0px;left:0px; height:" + $('#urlBox').height() + 'px'></div>');
          $('#urlBox').append(d);
  },
          resize: function(e, ui) {
          resizeURLFrame()  // resize the inner iFrame as the container is resized
  },
          stop: function(e, ui) {
                  $(window).resize(resizeURLBox); //add window resize events back
                  $(window).resize(resizeURLFrame);
                  $('.iframeCover').remove();
          }
  });        


VIOLA! I now have a pop-up that will bend to my will, and even resize itself on browser resize. It does it all!
Comments

1  1/23/2015 2:43:58 AM  Using jQuery resizable and draggable with fixed position pop up

2viagra_sale  9/19/2016 12:12:55 PM  viagra sale

{ Link } ,

3viagra_sale  9/19/2016 12:13:12 PM  viagra sale

{ Link } ,

4viagra_sale  9/19/2016 12:13:33 PM  viagra sale

{ Link } ,

5viagra_sale  9/19/2016 12:13:52 PM  viagra sale

I simply couldn't depart your web site prior to suggesting that I actually loved the usual info a person supply for your guests? Is gonna be again continuously in order to check up on new posts.

6via_gra_sale  9/19/2016 12:14:08 PM  via_gra sale

I simply couldn't depart your web site prior to suggesting that I actually loved the usual info a person supply for your guests? Is gonna be again continuously in order to check up on new posts.

7Daniel  9/20/2016 11:48:30 AM  Daniel

I appreciate your wordpress web template, exactly where did you down load it through?

8cialis  9/23/2016 6:28:33 AM  discount cialis online

Tag trappen { Link } , polen apotheke frem for elevatoren hver gang det er muligt.

9cialis  9/23/2016 6:28:53 AM  discount cialis online

{ Link } , , must not be used in men with cardiac disease for whom sexual activity is inadvisable.

10cialis  9/24/2016 12:06:11 PM  buy cialis omline

{ Link } , for daily use free trial , online cialis canada .

11Paul  9/24/2016 12:06:38 PM  Paul

Valuable information. Lucky me I found your site by accident, and I am shocked why this accident did not happened earlier! I bookmarked it.

12Paul  9/24/2016 12:07:00 PM  Paul

Valuable information. Lucky me I found your site by accident, and I am shocked why this accident did not happened earlier! I bookmarked it.

13street_fighter  10/4/2016 8:29:50 AM  street fighter

GENUINE { Link } , AND CIALIS FOR SALE from coquitlam British Columbia GreaterReply to Ad.

14street_fighter  10/4/2016 8:30:13 AM  street fighter

Is it possible to get a pill like { Link } , for women?

15cialis  10/18/2016 3:42:10 AM  cialis

These for makeup The scrapes or spit-ups buy { Link } , paypal payment in choosing the past!

16cialis  10/18/2016 3:42:27 AM  cialis

{ Link } , is a prescription only drug for very good reasons.

17cialis  10/19/2016 5:42:30 PM  cheap cialis online

You create a substitute for them them viagra which or { Link } , better is shipped.

18Joseph  10/19/2016 5:42:56 PM  Joseph

Hey very nice website!! Man .. Beautiful .. Amazing .. I'll bookmark your website and take the feeds alsoI'm happy to find numerous useful information here in the post, we need work out more techniques in this regard, thanks for sharing. . . . . .

19Joseph  10/19/2016 5:43:17 PM  Joseph

Hey very nice website!! Man .. Beautiful .. Amazing .. I'll bookmark your website and take the feeds alsoI'm happy to find numerous useful information here in the post, we need work out more techniques in this regard, thanks for sharing. . . . . .

20cheap_cialis  11/4/2016 7:18:18 AM  cheap cialis

Many Men Opting For Generic { Link } , .

21cheap_cialis  11/4/2016 7:18:36 AM  cheap cialis

Complete liquid { Link } , for sale love and.

22cheap_cialis  11/5/2016 7:40:30 AM  cheap cialis

This gives you exactly the same strength drug but at a fraction the usual price you pay for { Link } , .

23James  11/5/2016 7:40:57 AM  James

Hiya, I am really glad I have found this information. Nowadays bloggers publish just about gossips and web and this is really annoying. A good blog with interesting content, that is what I need. Thanks for keeping this website, I'll be visiting it. Do you do newsletters? Can not find it.

24James  11/5/2016 7:41:17 AM  James

Hiya, I am really glad I have found this information. Nowadays bloggers publish just about gossips and web and this is really annoying. A good blog with interesting content, that is what I need. Thanks for keeping this website, I'll be visiting it. Do you do newsletters? Can not find it.

25generic  11/24/2016 6:22:47 AM  cialis generic purchase

{ Link } , for on demand use discontinuedtreatment as a consequence of back pain/myalgia.

26generic  11/24/2016 6:23:06 AM  cialis generic purchase

Buy Get Low-cost { Link } , For The Best Deals.

27buy_cialis  11/25/2016 8:02:36 AM  buy cialis

{ Link } , will not be suitable for everyone.

28William  11/25/2016 8:03:00 AM  William

It is really a nice and helpful piece of info. Im glad that you shared this helpful information with us. Please keep us up to date like this. Thanks for sharing.

29William  11/25/2016 8:03:19 AM  William

It is really a nice and helpful piece of info. Im glad that you shared this helpful information with us. Please keep us up to date like this. Thanks for sharing.

30cialis  12/6/2016 3:39:26 AM  cialis

The { Link } , for sale vancouver had got into his fund and driven off; they followed him.

31cialis  12/6/2016 3:39:45 AM  cialis

{ Link } , May Not Prevent Impotence in Men Treated for Prostate Cancer .

32of  1/10/2017 2:03:39 PM  sale of viagra

I see sales for { Link } , are way down.

33of  1/10/2017 2:04:02 PM  sale of viagra

Buy Viagr'a for Less' from { Link } , O,nline+Pharmacy.

34viagra_online  1/10/2017 7:15:32 PM  viagra online

You can order a prescription for { Link } , from DrEd and use it to buy Viagra from your local pharmacy.

35Daniel  1/10/2017 7:15:57 PM  Daniel

Valuable information. Lucky me I found your site by accident, and I am shocked why this accident did not happened earlier! I bookmarked it.

36Daniel  1/10/2017 7:16:22 PM  Daniel

Valuable information. Lucky me I found your site by accident, and I am shocked why this accident did not happened earlier! I bookmarked it.

37does  2/13/2017 3:59:55 AM  women does viagra work

{ Link } , is often the first treatment tried for erectile dysfunction in men .

38does  2/13/2017 4:00:14 AM  women does viagra work

Reliable site for { Link } , jelly - Online pharmacy!

39viagra  2/17/2017 11:04:07 PM  order viagra online

And { Link } , for sale Sharpener continue temperatures.

40Joseph  2/17/2017 11:07:31 PM  Joseph

Hello There. I found your blog using msn. This is a really well written article. Ill make sure to bookmark it and return to read more of your useful information. Thanks for the post. I will definitely return.

41Joseph  2/17/2017 11:16:52 PM  Joseph

Hello There. I found your blog using msn. This is a really well written article. Ill make sure to bookmark it and return to read more of your useful information. Thanks for the post. I will definitely return.

42cheap_cialis  3/3/2017 7:35:00 AM  cheap cialis

{ Link } , (tadalafil) for Erectile Dysfunction: My Dr.

43cheap_cialis  3/3/2017 7:35:18 AM  cheap cialis

With { Link } , for daily use, you can be ready anytime the moment is right, even if it's not every day.

44no  3/8/2017 12:31:14 AM  http://pills1cia.com/

{ Link } , , this page for early part in nature.

45John  3/8/2017 12:34:41 AM  John

It is appropriate time to make some plans for the future and it is time to be happy. I have read this post and if I could I want to suggest you few interesting things or suggestions. Maybe you can write next articles referring to this article. I wish to read more things about it!