Skip to content

Instantly share code, notes, and snippets.

Created October 5, 2015 04:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/011e705d1ee4e8340495 to your computer and use it in GitHub Desktop.
Save anonymous/011e705d1ee4e8340495 to your computer and use it in GitHub Desktop.
$("#sun").draggable({
axis: "x",
drag: function() {
var xpos = parseFloat(this.style.left, 10) - 100;
var ypos = Math.sqrt(300 * 300 - xpos * xpos) * 0.75;
this.style["margin-top"] = (-ypos) + "px";
}
});
@masaeedu
Copy link

masaeedu commented Oct 5, 2015

var width = 300;
var rise = width / 2;

$("#sun").draggable({
axis: "x",
drag: function() {
var x = this.offsetLeft + (width / 2);
var y = this.offsetRight + (width / 2);

    var heightPct = 1 - ((x ^ 2) / (x + y)^2);
    this.style["margin-top"] = (heightPct * 30) + "px";
}

});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment