Skip to content

Instantly share code, notes, and snippets.

@vladholubiev
Created April 18, 2015 18:54
Show Gist options
  • Select an option

  • Save vladholubiev/cffd0a358f368bcc5e71 to your computer and use it in GitHub Desktop.

Select an option

Save vladholubiev/cffd0a358f368bcc5e71 to your computer and use it in GitHub Desktop.
Moving bus - jsbin.com/weruqidazu/2/edit?output
<!DOCTYPE html>
<html>
<head>
<script src="//code.jquery.com/jquery-2.1.1.min.js"></script>
</head>
<body>
<img style="position: fixed;" src="http://www.crk12.org/cms/lib7/DE01903180/Centricity/Domain/444/bus.gif" alt=""/>
</body>
</html>
(function() {
var leftMargin, maxWidth;
leftMargin = 0;
maxWidth = $(window).width();
setInterval(function() {
if (maxWidth - leftMargin > 0) {
$("img").css("left", leftMargin++);
} else {
leftMargin = 0 - $("img").width();
$("img").css("left", leftMargin);
}
}, 1);
}).call(this);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment