DEVHIDE
        • Home (current)
        • About
        • Contact
        • Cookie
        • Home (current)
        • About
        • Contact
        • Cookie
        • Disclaimer
        • Privacy
        • TOS
        Login Or Sign up

        jQuery UI draggable: Use other element for containment and snapTo calculation

        1.1k Views Asked by Thomas At 01 February 2012 at 14:45 2025-12-21T07:59:17.867798

        I have 2 elements that both need to be dragged. The simplified markup is as follows:

        <div class="wrapper">
            <img class="item" src="foo.jpg" />
            <ul class="buttons">
                <li>Crop</li>
                <li>Resize</li>
            </ul>
        </div>
        

        They need to be contained in an area and also snapTo certain elements in that area. The problem is that I want draggable to look at .item and not .wrapper when calculating how it should be contained. Because the buttons area positioned slightly outside .item.

        If I use draggable on .item, .wrapper does not move along.

        If I use draggable on .wrapper, .item can not be positioned completely to the top, right or bottom of the element used for containment.

        Simplified code:

        $('.wrapper').draggable ({
            containment: '.page',
            snap: '.page-grid',
            snapMode: 'inner',
            snapTolerance: 20
        });
        

        Explanation of the situation

        Does anybody have an idea on how to solve this? Your help is greatly appreciated.

        jquery user-interface draggable containment
        Original Q&A
        1

        There are 1 best solutions below

        1
        Christoph Christoph On 01 February 2012 at 14:56 BEST ANSWER

        if you don't have overflow:hidden applied to your wrapper then just make the wrapper exactly the same measurements as your item. You still can position your buttons with negative values like: bottom:-5px. This way they will stay the same way like you have them now with that slight padding on your wrapper.

        #wrapper{ padding:0 }
        .buttons{position:absolute; bottom:-5px;right:-5px}
        

        Related Questions in JQUERY

        • In Datatables, start value resets to 0, when column sorting
        • Bootstrap modal not showing at the desired position on a web page when the screen size is smaller
        • window.location.href redirects but is causing problems on the webpage
        • Using JQuery Date Slider
        • Storing selected language in localStorage
        • How to stop other divs from still showing when i click a different button?
        • Check multiple values with jQuery
        • Bootstrap component does not want to render in Datatables function
        • put white spaces when entering an amount moneytype symfony
        • Trouble accessing custom header in AJAX response using jQuery in Fiware Keyrock
        • I just cant make it work, HTML, JS and Firebase error
        • Didn't declared variable still not getting any error in JavaScript
        • Move element horizontally while scrolling vertically in pure JavaScript
        • allow multi carousel in same page
        • Embedded TikTok posts / thumbnail styling issue

        Related Questions in USER-INTERFACE

        • OS-wide text autocomplete service with popup
        • Bootstrap 5 tooltips not working in Laravel 9.x application
        • GUI window is not appearing
        • Responsive gui customtkinter
        • Unwanted text on created icon
        • Custom styled "Add to cart" button in WooCommerce product archive pages
        • Page behavior in flet works when used directly in `main`, but not in a UserControl?
        • How could I reuse the CTk tabviews in python GUI app?
        • mouse coordinates in image go below 0 and above width
        • Use the same button in different interfaces (JAVA)
        • Distributing a GTK4 Windows application
        • How to design the file operation interface involving status and transactions?
        • Creating a GUI application for creating graphs
        • How point to other link after login
        • How to align widget to another widget in Flutter

        Related Questions in DRAGGABLE

        • Vue 2 draggable not reactive when v-model value is an iterable of parent tag
        • can't drag boxes to specific time slot in weekly calendar
        • Flutter - Dragging a Draggable from drawer to body
        • Draggable Chrome Extension using iFrame
        • drag and drop box showing stop sign
        • Create a grid form to add components and move them to specific locations
        • WinAPI 32 and GDI+ move window when draggin a PNG image with some region with trasparency
        • cards dont always jump to make space for a new card when reordering list
        • Want to restrict the panResponder icon to move out of the screen
        • Is there any way to implement drag and drop sortable Ant Design Collapse?
        • How to make .draggable() work with click+drag rather than long-press+drag?
        • Dragged component overlapping/over drop target/component so onPointerOver/onPointerEnter event of below component not firing
        • Draggable flatlist not scrolling
        • How to set Caretposition via mouse click in content editable within a draggable in Firefox
        • Dragging a element at a position of Cursor in ReactJs

        Related Questions in CONTAINMENT

        • How to check if value "in" some collection *and* get it?
        • jQuery Draggable Modal within visible window, set dynamic containment not works when scroll
        • update containment bounds while dragging a UI draggable element
        • How to provide an argument to a view controller in containment?
        • When using ArrayList(Collection<? extends E> c) for a copy constructor I get two errors
        • jq select and contains error: null (null) and string ("randomtext1") cannot have their containment checked
        • Jquery - Draggable feature Containment property for a polygonal parent
        • Unfiling a document code from IBM knowledge center
        • Django - How do I create a model that contains a collection of its own type?
        • Multiple Bounding Boxes containment detection algorithm
        • SQL Server containment partial
        • Does the 'in' operator use "==" or "is" for comparisons?
        • JQuery-UI containment: 'parent' does not work
        • Compare two json files using jq or any other tools in bash
        • Two similar array-in-array containment tests. One passes, the other raises a ValueError. Why?

        Trending Questions

        • UIImageView Frame Doesn't Reflect Constraints
        • Is it possible to use adb commands to click on a view by finding its ID?
        • How to create a new web character symbol recognizable by html/javascript?
        • Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
        • Heap Gives Page Fault
        • Connect ffmpeg to Visual Studio 2008
        • Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
        • How to avoid default initialization of objects in std::vector?
        • second argument of the command line arguments in a format other than char** argv or char* argv[]
        • How to improve efficiency of algorithm which generates next lexicographic permutation?
        • Navigating to the another actvity app getting crash in android
        • How to read the particular message format in android and store in sqlite database?
        • Resetting inventory status after order is cancelled
        • Efficiently compute powers of X in SSE/AVX
        • Insert into an external database using ajax and php : POST 500 (Internal Server Error)

        Popular # Hahtags

        javascript python java c# php android html jquery c++ css ios sql mysql r reactjs

        Popular Questions

        • How do I undo the most recent local commits in Git?
        • How can I remove a specific item from an array in JavaScript?
        • How do I delete a Git branch locally and remotely?
        • Find all files containing a specific text (string) on Linux?
        • How do I revert a Git repository to a previous commit?
        • How do I create an HTML button that acts like a link?
        • How do I check out a remote Git branch?
        • How do I force "git pull" to overwrite local files?
        • How do I list all files of a directory?
        • How to check whether a string contains a substring in JavaScript?
        • How do I redirect to another webpage?
        • How can I iterate over rows in a Pandas DataFrame?
        • How do I convert a String to an int in Java?
        • Does Python have a string 'contains' substring method?
        • How do I check if a string contains a specific word?
        .

        Copyright © 2021 Jogjafile Inc.

        • Disclaimer
        • Privacy
        • TOS
        • Homegardensmart
        • Math
        • Aftereffectstemplates