Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7616023
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T02:47:22+00:00 2026-05-31T02:47:22+00:00

OK, here is my question. Using jQuery UI position. It is possible to position

  • 0

OK, here is my question.
Using jQuery UI position. It is possible to position an element in relation to another element on the screen. It sets the left and top css properties on the element being positioned which positions it on the screen.

What I want to do is instead of setting the left and top, I want to possibly set right and bottom instead so that if the positioned element grows or shrinks, it will grow / shrink in the correct direction.

Let me go into details.
Ok, what I want is if an element is positioned on it’s right, then I want to set the right css property instead of the left and if an element is positioned on its bottom, then I want to set bottom instead of top. I can do this using the using property of jQuery UI Position, but I run into problems with collision detection. If collision detection is set to flip and the element gets flipped, I want to detect this and figure out whether I need to set right instead of left and bottom instead of top. Check out the code below to get a better idea of what I’m trying to do.

$('#somediv').position({
    my: 'right bottom',
    at: 'right top',
    of: $('#someotherdiv'),
    offset: '0 5',
    collision: 'flip flip',
    using: function(pos) {

      // Figure out the right and bottom css properties 
      var right = $(window).width() - pos.left - $(this).outerWidth(true);
      var bottom = $(window).height() - pos.top - $(this).outerHeight(true);

      // Position the element so that right and bottom are set.
      $(this).css({left: '', right: right, top: '', bottom: bottom});  
    }
});

That works great, except when the div gets flipped from collision detection. If it gets flipped horizontally, I want to set left instead of right and if it gets flipped vertically I want to set top instead of bottom.

The ideal solution would be if there was a way to tell (in the using function) whether the element was flipped and in what directions. So, anyone have any ideas to figure out whether an element was flipped using collision detection?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T02:47:24+00:00Added an answer on May 31, 2026 at 2:47 am

    OK, figured it out…. Here is my attempt to explain how I made it work.
    What you have to do is call position again within the using function. Call it once without collision detection and once with collision detection. If the position changes, then it was flipped. Here is some example code with comments.

    $('#somediv').position({
        my: 'right bottom',
        at: 'right top',
        of: $('#someotherdiv'),
        offset: '0 5',
        collision: 'flip flip',
        using: function (pos1) {
    
            // OK, we got a position once inside the pos1 variable,
            // let's position it again this time without collision detection.
            $(this).position({
                my: 'right bottom',
                at: 'right top',
                of: $('#someotherdiv'),
                offset: '0 5',
                collision: 'none none',
                using: function(pos2) {
                    var hpos = 'right';
                    var vpos = 'bottom';
    
                    // Check to see if it was flipped horizontal
                    if (pos1.left != pos2.left) {
                        /* It was flipped horizontally so position is now
                           my: 'left bottom',
                           at: 'left top'
                        */
                        hpos = 'left';
                    }
    
                    // Check to see if it was flipped vertical
                    if (pos1.top != pos2.top) {
                        /* It was flipped vertically */
                        vpos = 'top';
                    }
    
                    // Figure out the right and bottom css properties 
                    var right = $(window).width() - pos1.left - $(this).outerWidth(true);
                    var bottom = $(window).height() - pos1.top - $(this).outerHeight(true);
    
                    // Set the horizontal position
                    if (hpos == 'right') {
                        $(this).css({left: '', right: right});
                    } else {
                        $(this).css({left: pos1.left, right: ''});
                    }
    
                    // Set the vertical position
                    if (vpos == 'bottom') { 
                        $(this).css({top: '', bottom: bottom});
                    } else {
                        $(this).css({top: pos1.top, bottom: ''});
                    }
                }
            });
        }
    });
    

    If anyone has a more efficient idea, please let me know. Thanks.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using the jQuery Cycle plugin. The page in question is here: http://harrisonfjord.com/folio/test.html The
quick question here. Normally, using JQuery, if I want to pass the value from
This is really more of a CSS question than a jQuery question. I'm using
I asked a question here : When To Use IEquatable And Why about using
Here's my question. Right now I have a Linux server application (written using C++
I'm using lucene in my project. Here is my question: should I use lucene
Despite an earlier question ( asked here ), our project is constrained to using
So I decided to start using prototype and here's my first question. I'm trying
For more info, see my other question, here . So anyway, I'm using BigDecimals
I have a feeling that this probably is not possible using strictly CSS, but,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.