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 9257113
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T12:07:15+00:00 2026-06-18T12:07:15+00:00

I drag horizontally a larger-than-browser div but want it to snap to the wrapper

  • 0

I drag horizontally a larger-than-browser div but want it to snap to the wrapper when reaching the end left and right. I can not do it with “containment” as the dragging is not working properly when the dragged div is larger than its containment:

$( "#dragable" ).draggable({ cursor: "e-resize", axis: "x", containment: "document" });

http://jsfiddle.net/xBVYT/320/

For this reason I remove the “containment” but then the dragged div is going out of the browser window:

$( "#dragable" ).draggable({ cursor: "e-resize", axis: "x" });

http://jsfiddle.net/xBVYT/325/

Any help will be much appreciated.

  • 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-06-18T12:07:16+00:00Added an answer on June 18, 2026 at 12:07 pm

    By controlling the drag event, you can prevent the draggable from moving out of the margins:
    See my jsfiddle
    Here are the options with the drag event function:

    $( "#dragable" ).draggable({
        cursor: "e-resize"
        , axis: "x" 
        , drag: function(event, ui) {
            var $container = $(this).closest(".wrap");
            var container_left = $container.position().left;
            var container_right = $container.position().left + $container.width();
            var drag_left = ui.offset.left;
            var drag_right = ui.offset.left + $(this).width();
            if (drag_left > container_left) {
                return false;
            };
            if (drag_right < container_right) {
                return false;
            };
        }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to place panels horizontally, but when I drag panels they are going
I'm using this tiny drag plugin to drag div.slider horizontally across it's div.container. I
How i can adjust the jquery jscrollpane horizontal scroll with scroll drag right to
I currently have something working where I can drag a box horizontally on the
I want to drag&drop from treeview to datagrid view. The code for drag is
i like to drag this object vertically instead of horizontally, which is doin it
Maybe I'm afflicted with myopia and just can't see what's wrong anymore but I
I have a detail view Fragment which I want to scroll Horizontally as well
I am using a scrollviewer to show some buttons displayed horizontally, I can use
I want to drag an uiimageview only in horizontal from a point1 to a

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.