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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T18:23:47+00:00 2026-06-05T18:23:47+00:00

Usually I prefer to write my own solutions for trivial problems because generally plugins

  • 0

Usually I prefer to write my own solutions for trivial problems because generally plugins add a lot of unneeded functionality and increase your project in size. Size makes a page slower and a 30k difference (compared to jquery draggable) in a 100k pageviews / day website makes a big difference in the bill. I already use jquery and I think that’s all I need for now, so please, don’t tell me to use another plugin or framework to drag things around.

Whit that in mind I wrote the following code, to allow a box to be draggable around. The code works just fine (any tip about the code itself will be great appreciate), but I got a small little glitch.

When I drag the box to the browser right edge limit, a horizontal scroll bar appears, the window width gets bigger because of the box. The desirable behavior is to see no horizontal scroll bar, but allow to put part of the box outside the window area, like a windows window do.

Any tips?

CSS:

.draggable {
    position: absolute;
    cursor: move;
    border: 1px solid black;
}

Javascript:

$(document).ready(function() {
    var x = 0;
    var y = 0;
    $("#d").live("mousedown", function() {
        var element = $(this);
        $(document).mousemove(function(e) {
            var x_movement = 0;
            var y_movement = 0;
            if (x == e.pageX || x == 0) {
                x = e.pageX;
            } else {
                x_movement = e.pageX - x;
                x = e.pageX;
            }
            if (y == e.pageY || y == 0) {
                y = e.pageY;
            } else {
                y_movement = e.pageY - y;
                y = e.pageY;
            }
            var left = parseFloat(element.css("left")) + x_movement;
            element.css("left", left);
            var top = parseFloat(element.css("top")) + y_movement;
            element.css("top", top);
            return false;
        });
    });
    $(document).mouseup(function() {
        x = 0;
        y = 0;
        $(document).unbind("mousemove");
    });
});​

HTML:

<div id="d" style="width: 100px; left: 0px; height: 100px; top: 0px;" class="draggable">a</div>
  • 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-05T18:23:48+00:00Added an answer on June 5, 2026 at 6:23 pm

    For a simple solution, you could just add some CSS to the draggable object’s container to prevent the scrollbars.

    body { overflow: hidden; }
    

    jsFiddle: http://jsfiddle.net/F894P/

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

Sidebar

Related Questions

I've been doing a lot of calculating stuff nowadays. Usually I prefer to do
Usually i write my where statements as WHERE key=@0 then add a param. Now
I usually prefer the extension methods, because they i find them easier to read,
I'd usually prefer to create virtualenvs with --no-site-packages option for more isolation, and also
I usually write C code in C89, now some features of C99 (like intxx_t
Do you prefer... 1- Write the whole application, then set up routing/url rewriting 2-
I never liked implicit operators (prefer extension methods) because it is hard to see
I usually prefer to code with a black background and white/coloured text but I
I usually prefer linux for programming( i program in django on Ubuntu). But often
Usually I tend to install things via the package manager, for unixy stuff. However,

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.