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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T20:26:11+00:00 2026-05-30T20:26:11+00:00

I’m looking for a way to simulate resistance using the jQueryUI draggable plugin (similar

  • 0

I’m looking for a way to simulate resistance using the jQueryUI draggable plugin (similar to this effect). At the bottom of the draggable documentation it mentions:

“To manipulate the position of a draggable during drag, you can either
use a wrapper as the draggable helper and position the wrapped element
with absolute positioning, or you can correct internal values like so:
$(this).data(‘draggable’).offset.click.top -= x”.

Geometry not being my strong suit I was looking for help on how to best achieve the effect of resistance when dragging something. I thought that using this tip above, I could change the distance the draggable is moved using a geometric function. I’m not sure if the best term is resistance or elasticity, but I’m looking for the feel as if an element is attached to a point by a rubber band or bungee cord so that the further you drag, the less the object moves.

For example, say I want to drag an object a total distance of 500 pixels (in any direction). I would like the resistance effect to increase the closer to 500 pixels away from the starting point I get. I’ve looked around and haven’t seen anything like this.

Update:

I created a basic jsFiddle that calculates the distance an item has been dragged at http://jsfiddle.net/Z8m4B/

The calculation is:

var x1=x2=y1=y2=0;
$("#draggable").draggable({
    start: function(e, ui) {
        y1 = ui.position.top;
        x1 = ui.position.left;
    },
    stop: function(e, ui) {
        y2 = ui.position.top;
        x2 = ui.position.left;        
        dist = parseInt(Math.sqrt(Math.pow((x2-x1),2)+Math.pow((y2-y1),2)), 10);
        console.log(dist);
    }
});

Obviously I would want to change the distance during the drag event and not on stop. Does anyone know how a function to create this resistance or stretch effect?

  • 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-30T20:26:13+00:00Added an answer on May 30, 2026 at 8:26 pm

    you can try with this http://jsfiddle.net/sAX4W/ with the drag event you can calculate the distance and get a % from the real distance

    var x1 = x2 = y1 = y2 = 0;
    $("#draggable").draggable({
        revert: true,
        revertDuration: 100,
        axis: 'y',
        drag: function(e, ui) {
            y2 = ui.position.top;
            x2 = ui.position.left;
            dist = parseInt(Math.sqrt(Math.pow((x2 - x1), 2) + Math.pow((y2 - y1), 2)), 10);
            ui.position.top = ui.position.top * (1 - (dist / 1000));
        },
        start: function(e, ui) {
            y1 = ui.position.top;
            x1 = ui.position.left;
        },
        stop: function(e, ui) {
        }
    });​
    

    edit

    you can try this with both axis http://jsfiddle.net/2QndJ/

    var x1 = x2 = y1 = y2 = 0;
    $("#draggable").draggable({
        revert: true,
        revertDuration: 100,
    
        drag: function(e, ui) {
            y2 = ui.position.top;
            x2 = ui.position.left;
            dist = parseInt(Math.sqrt(Math.pow((x2 - x1), 2) + Math.pow((y2 - y1), 2)), 10);
    
            ui.position.top = ui.position.top * (1 - (dist / 1000));
            ui.position.left = ui.position.left * (1 - (dist / 1000));
        },
        start: function(e, ui) {
            y1 = ui.position.top;
            x1 = ui.position.left;
        },
        stop: function(e, ui) {
        }
    });​
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using the jquery-ui-dialog plugin I am looking for way to refresh the
I am using codeigniter and looking a way to enable directly editting of doc
I looking for a way to programmatically start a VOIP call using the SIP
Looking for a way to simulate nested loops (or a cartesian product) i came
I'm looking for a way to simulate a projector in wpf 3D : i've
I'm prototyping a thin client UI using extjs and am looking for an effect
looking a way to make a toggle on doubleclick, this is my code: $('#mydiv').toggle(function()
I am looking for a way to simulate with Google Analytics _gaq.push that the
I'm looking for a way to simulate minibuffer input. So, some-func takes some input
I am using AS2 and I'm looking for a way to scale an MC

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.