Skip to content

Instantly share code, notes, and snippets.

@binjoo
Created November 2, 2012 08:21
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save binjoo/3999461 to your computer and use it in GitHub Desktop.
Save binjoo/3999461 to your computer and use it in GitHub Desktop.
HTML:CSS:JQUERY:仿Flickr加载动画效果
<!DOCTYPE HTML>
<html>
<head>
<title>JQuery Flickr Loading Animation</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript">
$(function() {
var wwidth = $(window).width();
var bluewidth = $("#shapeblue").width();
$("#shapeblue").css("left", (wwidth/2) - bluewidth);
var bluepos = $("#shapeblue").position();
var movex = $("#shapeblue").width() + 4;
$("#shapepink").css("left", bluepos.left + movex);
var playAnimate;
function moveleft(el) {
$(el).animate({
left: '+='+movex
}, 800, function() {
$(el).css("z-index", "-100");
});
}
function moveright(el) {
$(el).animate({
left: '-='+movex
}, 800, function() {
$(el).css("z-index", "100");
});
}
function playAnimation() {
moveleft("#shapeblue");
moveright("#shapeblue");
moveright("#shapepink");
moveleft("#shapepink");
}
$("#playbtn").click(function() {
if ($(this).text() == "Start") {
playAnimate = setInterval(playAnimation, 800);
$(this).text("Stop");
} else {
clearInterval(playAnimate);
$(this).text("Start");
}
return false;
});
});
</script>
<style type="text/css">
* {
font-family: Arial, "Free Sans";
}
#container {
text-align: center;
width: 800px;
padding: 40px 0;
margin: 0 auto;
}
#container a {
background: #0063dc;
color: #ffffff;
text-decoration: none;
padding: 5px 8px;
font-size: 18px;
-webkit-border-radius: 0.5em;
-moz-border-radius: 0.5em;
border-radius: 0.5em;
}
#container a:hover {
background: #ff0084;
}
#text {
color: #0063dc;
margin-top: 30px;
font-size: 12px;
font-weight: bold;
}
.bar {
width: 250px;
height: 250px;
-webkit-border-radius: 7.5em;
-moz-border-radius: 7.5em;
border-radius: 7.5em;
margin-right: 2px;
position: absolute;
}
#shapeblue {
background: #0063dc;
z-index: 1;
}
#shapepink {
background: #ff0084;
z-index: 0;
}
</style>
</head>
<body>
<div id="container">
<div id="control">
<a href="" id="playbtn">Start</a>
<div id="text"> Click "Play" To Start Animation</div>
</div>
</div>
<div id="shapeblue" class="bar"></div>
<div id="shapepink" class="bar"></div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment