Created
January 9, 2015 18:13
-
-
Save OfTheDelmer/529f878c2aafc4bdbf77 to your computer and use it in GitHub Desktop.
// source http://jsbin.com/koqale
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<script src="http://code.jquery.com/jquery-1.11.1.min.js"></script> | |
<meta charset="utf-8"> | |
<title>JS Bin</title> | |
</head> | |
<body> | |
<script id="jsbin-javascript"> | |
// Wait for window onload | |
$(function (){ | |
var imgSrc = "http://tctechcrunch2011.files.wordpress.com/2012/10/haters-gonna-hate.gif"; | |
var $window = $(window); | |
var winWidth = $window.innerWidth(); | |
var winHeight = $window.innerHeight(); | |
var $body = $("body"); | |
var $img = $("<img>"); | |
$img.attr("src", imgSrc); | |
$img.width("200px"); | |
$img.height("200px"); | |
$body.append($img); | |
var direction = 1; | |
var rate = 200; | |
setInterval(function(){ | |
var leftOffset = $img.offset().left; | |
console.log(leftOffset, $img.width(), winWidth); | |
if (winWidth < $img.width() +leftOffset || leftOffset < -100 ) { | |
direction = direction * -1; | |
} | |
console.log("running"); | |
$img.offset({ | |
left: (leftOffset + direction*20) | |
}); | |
},rate) | |
}); | |
</script> | |
<script id="jsbin-source-html" type="text/html"><!DOCTYPE html> | |
<html> | |
<head> | |
<script src="//code.jquery.com/jquery-1.11.1.min.js"><\/script> | |
<meta charset="utf-8"> | |
<title>JS Bin</title> | |
</head> | |
<body> | |
</body> | |
</html></script> | |
<script id="jsbin-source-javascript" type="text/javascript">// Wait for window onload | |
$(function (){ | |
var imgSrc = "http://tctechcrunch2011.files.wordpress.com/2012/10/haters-gonna-hate.gif"; | |
var $window = $(window); | |
var winWidth = $window.innerWidth(); | |
var winHeight = $window.innerHeight(); | |
var $body = $("body"); | |
var $img = $("<img>"); | |
$img.attr("src", imgSrc); | |
$img.width("200px"); | |
$img.height("200px"); | |
$body.append($img); | |
var direction = 1; | |
var rate = 200; | |
setInterval(function(){ | |
var leftOffset = $img.offset().left; | |
console.log(leftOffset, $img.width(), winWidth); | |
if (winWidth < $img.width() +leftOffset || leftOffset < -100 ) { | |
direction = direction * -1; | |
} | |
console.log("running"); | |
$img.offset({ | |
left: (leftOffset + direction*20) | |
}); | |
},rate) | |
});</script></body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Wait for window onload | |
$(function (){ | |
var imgSrc = "http://tctechcrunch2011.files.wordpress.com/2012/10/haters-gonna-hate.gif"; | |
var $window = $(window); | |
var winWidth = $window.innerWidth(); | |
var winHeight = $window.innerHeight(); | |
var $body = $("body"); | |
var $img = $("<img>"); | |
$img.attr("src", imgSrc); | |
$img.width("200px"); | |
$img.height("200px"); | |
$body.append($img); | |
var direction = 1; | |
var rate = 200; | |
setInterval(function(){ | |
var leftOffset = $img.offset().left; | |
console.log(leftOffset, $img.width(), winWidth); | |
if (winWidth < $img.width() +leftOffset || leftOffset < -100 ) { | |
direction = direction * -1; | |
} | |
console.log("running"); | |
$img.offset({ | |
left: (leftOffset + direction*20) | |
}); | |
},rate) | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment