Skip to content

Instantly share code, notes, and snippets.

@smuniza1
Created October 18, 2015 19:32
Show Gist options
  • Save smuniza1/953d51af9234bc1051ca to your computer and use it in GitHub Desktop.
Save smuniza1/953d51af9234bc1051ca to your computer and use it in GitHub Desktop.
<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: 20%;
left: 10%;
}
.image {
background: url(http://i.imgur.com/DGkZYZQ.png);
}
</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",
containment: 'body',
drag: function() {
var x = sun.offset().left + (sun.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) + "%";
}
});
$("#sun").bind("drag", function(event, ui) {
var halfWidth = $(window).width() / 2;
var left = $(this).offset().left + 100;
var windowWIdth = $(window).width() - 200;
var image = $('.image');
$('.position').html(left);
$('.window').html(windowWIdth);
if(left < halfWidth) {
image.css('background-image', url('http://i.imgur.com/f3UFHb7.png'));
}
if (left > windowWIdth) {
image.css('background-image', url('http://i.imgur.com/o7cwLDa.png'));
}
});
</script>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment