Skip to content

Instantly share code, notes, and snippets.

@masaeedu
Forked from anonymous/gist:011e705d1ee4e8340495
Last active October 5, 2015 05:51
Show Gist options
  • Save masaeedu/d71f14c3fc44ec692449 to your computer and use it in GitHub Desktop.
Save masaeedu/d71f14c3fc44ec692449 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<style>
/* Colors */
body {
background: url(http://i.imgur.com/aZty7Mq.png);
animation: mymove 4s linear infinite;
-webkit-animation: mymove 4s linear infinite;
-moz-animation: mymove 4s linear infinite;
}
@keyframes mymove {
0% { background-position: 0 0; }
50% { background-position: 40% 0; }
}
#sun {
position: absolute;
width: 300px;
height: 300px;
top: 30%;
left: 10%;
}
</style>
<html>
<body>
<img id="sun" src="http://i.imgur.com/DGkZYZQ.png">
</body>
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<script>
var width = 300;
var sun = $("#sun");
sun.draggable({
axis: "x",
drag: function() {
var x = sun.offset().left + (width / 2);
var total = $(window).width();
var heightPct = Math.pow((total/2) - x, 2) / Math.pow($(window).width() / 2, 2);
console.log(x, $(window).width(), heightPct * 100);
this.style["margin-top"] = "" + Math.round(heightPct * 30) + "%";
}
});
</script>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment