Initializing
Liveweave
Web
expand_more
home
Home
data_object
CSS Explorer
arrow_outward
Palette
Color Explorer
arrow_outward
Polyline
Graphics Editor
arrow_outward
outbox_alt
Generative AI
arrow_outward
frame_source
Python Playground
New
arrow_outward
build
Tools
expand_more
restart_alt
Load "Hello Weaver!"
post_add
Generate Lorem ipsum...
code
Format HTML
code_blocks
Format CSS
data_object
Format JavaScript
library_add
Library
expand_more
A
Algolia JS
Animate CSS
Apex Charts JS
B
Bulma CSS
Bootstrap
C
Chart JS
Chartist
Create JS
D
D3
Dojo
F
Foundation
Fullpage JS
G
Granim JS
Google Charts
H
Halfmoon
J
jQuery
M
Materialize
Moment JS
Masonry JS
Milligram CSS
P
Pure CSS
Primer CSS
Popper JS
Pattern CSS
Picnic CSS
R
React JS
Raphael JS
Raisin CSS
S
Semantic UI
Skeleton CSS
Spectre CSS
Tachyons CSS
T
Tailwind
Three JS
U
UI Kit
Vis JS
W
Water CSS
download
Download
expand_more
developer_mode
Download as HTML
folder_zip
Download as .ZIP
cloud_upload
Save
account_circle
Login
settings
Settings
expand_more
14
px
Live mode
Night mode
Line number
Mini map
Word wrap
sync_alt
Reset Settings
smart_display
Run
<!DOCTYPE html> <html lang="en"> <head> <script src="http://cdnjs.cloudflare.com/ajax/libs/modernizr/2.6.2/modernizr.min.js"></script> <meta charset="UTF-8" /> <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> <title>Creating an Animated 3D Bouncing Ball with CSS3</title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="description" content="Tutorial about how to create an animated 3D bouncing ball with CSS3" /> <meta name="keywords" content="css3, animation, transition, bouncing, 3d, ball, round, web development, web design, tutorial, Daniel Sternlicht" /> <meta name="author" content="Daniel Sternlicht for Codrops" /> <link href='http://fonts.googleapis.com/css?family=Open+Sans+Condensed:700,300,300italic' rel='stylesheet' type='text/css'> </head> <body> <div class="container"> <header> <h1>3D Bouncing Ball <span>with CSS3</span></h1> <h2>Create an animated 3D bouncing ball using CSS3 transitions and animations</h2> <div class="support-note"><!-- with modernizr we check browser support --> <span class="no-cssanimations">CSS animations are not supported in your browser</span> <span class="no-csstransforms">CSS transforms are not supported in your browser</span> <!--span class="no-csstransforms3d">CSS 3D transforms are not supported in your browser</span--> <span class="no-csstransitions">CSS transitions are not supported in your browser</span> </div> </header> <section class="main"> <h3 class="explanation">Click and hold the ball to make it move back!</h3> <div id="ballWrapper"> <div id="ball"></div> <div id="ballShadow"></div> </div> </section> </div> </body> </html>
@import url('normalize.css'); /* General Demo Style */ body{ font-family: 'Open Sans Condensed','Arial Narrow', serif; font-weight: 400; font-size: 15px; color: #333; -webkit-font-smoothing: antialiased; -moz-font-smoothing: antialiased; font-smoothing: antialiased; } .container{ width: 100%; position: relative; } .clr{ clear: both; padding: 0; height: 0; margin: 0; } .container > header{ margin: 10px; padding: 20px 10px 10px 10px; position: relative; display: block; text-shadow: 1px 1px 1px rgba(0,0,0,0.2); text-align: center; } .container > header h1{ font-size: 40px; line-height: 40px; margin: 0; position: relative; font-weight: 300; color: #186B9E; text-shadow: 1px 1px 1px rgba(255,255,255,0.7); } .container > header h1 span{ font-weight: 700; } .container > header h2{ font-size: 14px; font-weight: 300; margin: 0; padding: 15px 60px 15px; border-bottom: 1px solid #ddd; box-shadow: 0 1px 0 rgba(255,255,255,0.6); color: #8c8c8c; font-family: Cambria, Georgia, serif; font-style: italic; text-shadow: 1px 1px 1px rgba(255,255,255,0.9); } /* Header Style */ .codrops-top{ line-height: 24px; font-size: 11px; background: #fff; background: rgba(255, 255, 255, 0.6); text-transform: uppercase; z-index: 9999; position: relative; font-family: Cambria, Georgia, serif; box-shadow: 1px 0px 2px rgba(0,0,0,0.2); } .codrops-top a{ padding: 0px 10px; letter-spacing: 1px; color: #333; display: inline-block; } .codrops-top a:hover{ background: rgba(255,255,255,0.3); } .codrops-top span.right{ float: right; } .codrops-top span.right a{ float: left; display: block; } .explanation { text-align: center; color: #888; text-shadow: 1px 1px 1px rgba(255,255,255,0.7); -webkit-touch-callout: none; -webkit-user-select: none; -khtml-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none; } .support-note span{ color: #ac375d; font-size: 16px; display: none; font-weight: bold; text-align: center; padding: 5px 0; } .no-cssanimations .support-note span.no-cssanimations, .no-csstransforms .support-note span.no-csstransforms, .no-csstransforms3d .support-note span.no-csstransforms3d, .no-csstransitions .support-note span.no-csstransitions{ display: block; } /* 3D Bouncing ball */ #ballWrapper { width: 140px; height: 300px; position: fixed; left: 50%; top: 35%; margin-left: -70px; z-index: 100; -webkit-transform: scale(1); -moz-transform: scale(1); -ms-transform: scale(1); -o-transform: scale(1); transform: scale(1); -webkit-transition: all 5s linear 0s; -moz-transition: all 5s linear 0s; transition: all 5s linear 0s; cursor: pointer; } #ballWrapper:active { -webkit-transform: scale(0); -moz-transform: scale(0); -ms-transform: scale(0); -o-transform: scale(0); transform: scale(0); cursor: pointer; } #ball { width: 140px; height: 140px; border-radius: 70px; background: rgb(187,187,187); background: url(data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiA/Pgo8c3ZnIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgd2lkdGg9IjEwMCUiIGhlaWdodD0iMTAwJSIgdmlld0JveD0iMCAwIDEgMSIgcHJlc2VydmVBc3BlY3RSYXRpbz0ibm9uZSI+CiAgPGxpbmVhckdyYWRpZW50IGlkPSJncmFkLXVjZ2ctZ2VuZXJhdGVkIiBncmFkaWVudFVuaXRzPSJ1c2VyU3BhY2VPblVzZSIgeDE9IjAlIiB5MT0iMCUiIHgyPSIwJSIgeTI9IjEwMCUiPgogICAgPHN0b3Agb2Zmc2V0PSIwJSIgc3RvcC1jb2xvcj0iI2JiYmJiYiIgc3RvcC1vcGFjaXR5PSIxIi8+CiAgICA8c3RvcCBvZmZzZXQ9Ijk5JSIgc3RvcC1jb2xvcj0iIzc3Nzc3NyIgc3RvcC1vcGFjaXR5PSIxIi8+CiAgPC9saW5lYXJHcmFkaWVudD4KICA8cmVjdCB4PSIwIiB5PSIwIiB3aWR0aD0iMSIgaGVpZ2h0PSIxIiBmaWxsPSJ1cmwoI2dyYWQtdWNnZy1nZW5lcmF0ZWQpIiAvPgo8L3N2Zz4=); background: -moz-linear-gradient(top, rgba(187,187,187,1) 0%, rgba(119,119,119,1) 99%); background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,rgba(187,187,187,1)), color-stop(99%,rgba(119,119,119,1))); background: -webkit-linear-gradient(top, rgba(187,187,187,1) 0%,rgba(119,119,119,1) 99%); background: -o-linear-gradient(top, rgba(187,187,187,1) 0%,rgba(119,119,119,1) 99%); background: -ms-linear-gradient(top, rgba(187,187,187,1) 0%,rgba(119,119,119,1) 99%); background: linear-gradient(top, rgba(187,187,187,1) 0%,rgba(119,119,119,1) 99%); filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#bbbbbb', endColorstr='#777777',GradientType=0 ); box-shadow: inset 0 -5px 15px rgba(255,255,255,0.4), inset -2px -1px 40px rgba(0,0,0,0.4), 0 0 1px #000; position: absolute; top: 0; z-index: 11; -webkit-animation: jump 1s infinite; -moz-animation: jump 1s infinite; -o-animation: jump 1s infinite; -ms-animation: jump 1s infinite; animation: jump 1s infinite; cursor: pointer; } #ball::after { content: ""; width: 80px; height: 40px; position: absolute; left: 30px; top: 10px; z-index: 10; background: url(data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiA/Pgo8c3ZnIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgd2lkdGg9IjEwMCUiIGhlaWdodD0iMTAwJSIgdmlld0JveD0iMCAwIDEgMSIgcHJlc2VydmVBc3BlY3RSYXRpbz0ibm9uZSI+CiAgPGxpbmVhckdyYWRpZW50IGlkPSJncmFkLXVjZ2ctZ2VuZXJhdGVkIiBncmFkaWVudFVuaXRzPSJ1c2VyU3BhY2VPblVzZSIgeDE9IjAlIiB5MT0iMCUiIHgyPSIwJSIgeTI9IjEwMCUiPgogICAgPHN0b3Agb2Zmc2V0PSIwJSIgc3RvcC1jb2xvcj0iI2U4ZThlOCIgc3RvcC1vcGFjaXR5PSIxIi8+CiAgICA8c3RvcCBvZmZzZXQ9IjElIiBzdG9wLWNvbG9yPSIjZThlOGU4IiBzdG9wLW9wYWNpdHk9IjEiLz4KICAgIDxzdG9wIG9mZnNldD0iMTAwJSIgc3RvcC1jb2xvcj0iI2ZmZmZmZiIgc3RvcC1vcGFjaXR5PSIwIi8+CiAgPC9saW5lYXJHcmFkaWVudD4KICA8cmVjdCB4PSIwIiB5PSIwIiB3aWR0aD0iMSIgaGVpZ2h0PSIxIiBmaWxsPSJ1cmwoI2dyYWQtdWNnZy1nZW5lcmF0ZWQpIiAvPgo8L3N2Zz4=); background: -moz-linear-gradient(top, rgba(232,232,232,1) 0%, rgba(232,232,232,1) 1%, rgba(255,255,255,0) 100%); background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,rgba(232,232,232,1)), color-stop(1%,rgba(232,232,232,1)), color-stop(100%,rgba(255,255,255,0))); background: -webkit-linear-gradient(top, rgba(232,232,232,1) 0%,rgba(232,232,232,1) 1%,rgba(255,255,255,0) 100%); background: -o-linear-gradient(top, rgba(232,232,232,1) 0%,rgba(232,232,232,1) 1%,rgba(255,255,255,0) 100%); background: -ms-linear-gradient(top, rgba(232,232,232,1) 0%,rgba(232,232,232,1) 1%,rgba(255,255,255,0) 100%); background: linear-gradient(top, rgba(232,232,232,1) 0%,rgba(232,232,232,1) 1%,rgba(255,255,255,0) 100%); filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#e8e8e8', endColorstr='#00ffffff',GradientType=0 ); border-radius: 40px / 20px; } #ballShadow { position: absolute; left: 50%; bottom: 0; z-index: 10; margin-left: -30px; width: 60px; height: 75px; background: rgba(20, 20, 20, .1); box-shadow: 0px 0 20px 35px rgba(20,20,20,.1); border-radius: 30px / 40px; -webkit-transform: scaleY(.3); -moz-transform: scaleY(.3); -ms-transform: scaleY(.3); -o-transform: scaleY(.3); transform: scaleY(.3); -webkit-animation: shrink 1s infinite; -moz-animation: shrink 1s infinite; -o-animation: shrink 1s infinite; -ms-animation: shrink 1s infinite; animation: shrink 1s infinite; } /* Animations */ @-webkit-keyframes jump { 0% {top: 0; -webkit-animation-timing-function: ease-in; } 40% {} 50% {top: 140px; height: 140px; -webkit-animation-timing-function: ease-out; } 55% {top: 160px; height: 120px; border-radius: 70px / 60px; -webkit-animation-timing-function: ease-in;} 65% {top: 120px; height: 140px; border-radius: 70px; -webkit-animation-timing-function: ease-out;} 95% { top: 0; -webkit-animation-timing-function: ease-in; } 100% {top: 0; -webkit-animation-timing-function: ease-in; } } @-moz-keyframes jump { 0% {top: 0; -moz-animation-timing-function: ease-in; } 40% {} 50% {top: 140px; height: 140px; -moz-animation-timing-function: ease-out; } 55% {top: 160px; height: 120px; border-radius: 70px / 60px; -moz-animation-timing-function: ease-in;} 65% {top: 120px; height: 140px; border-radius: 70px; -moz-animation-timing-function: ease-out;} 95% { top: 0; -moz-animation-timing-function: ease-in; } 100% {top: 0; -moz-animation-timing-function: ease-in; } } @-o-keyframes jump { 0% {top: 0; -o-animation-timing-function: ease-in; } 40% {} 50% {top: 140px; height: 140px; -o-animation-timing-function: ease-out; } 55% {top: 160px; height: 120px; border-radius: 70px / 60px; -o-animation-timing-function: ease-in;} 65% {top: 120px; height: 140px; border-radius: 70px; -o-animation-timing-function: ease-out;} 95% { top: 0; -o-animation-timing-function: ease-in; } 100% {top: 0; -o-animation-timing-function: ease-in; } } @-ms-keyframes jump { 0% {top: 0; -ms-animation-timing-function: ease-in; } 40% {} 50% {top: 140px; height: 140px; -ms-animation-timing-function: ease-out; } 55% {top: 160px; height: 120px; border-radius: 70px / 60px; -ms-animation-timing-function: ease-in;} 65% {top: 120px; height: 140px; border-radius: 70px; -ms-animation-timing-function: ease-out;} 95% { top: 0; -ms-animation-timing-function: ease-in; } 100% {top: 0; -ms-animation-timing-function: ease-in; } } @keyframes jump { 0% { top: 0; animation-timing-function: ease-in; } 50% { top: 140px; height: 140px; animation-timing-function: ease-out; } 55% { top: 160px; height: 120px; border-radius: 70px / 60px; animation-timing-function: ease-in; } 65% { top: 120px; height: 140px; border-radius: 70px; animation-timing-function: ease-out; } 95% { top: 0; animation-timing-function: ease-in; } 100% { top: 0; animation-timing-function: ease-in; } } @-webkit-keyframes shrink { 0% { bottom: 0; margin-left: -30px; width: 60px; height: 75px; background: rgba(20, 20, 20, .1); box-shadow: 0px 0 20px 35px rgba(20,20,20,.1); border-radius: 30px / 40px; -webkit-animation-timing-function: ease-in; } 50% { bottom: 30px; margin-left: -10px; width: 20px; height: 5px; background: rgba(20, 20, 20, .3); box-shadow: 0px 0 20px 35px rgba(20,20,20,.3); border-radius: 20px / 20px; -webkit-animation-timing-function: ease-out; } 100% { bottom: 0; margin-left: -30px; width: 60px; height: 75px; background: rgba(20, 20, 20, .1); box-shadow: 0px 0 20px 35px rgba(20,20,20,.1); border-radius: 30px / 40px; -webkit-animation-timing-function: ease-in; } } @-moz-keyframes shrink { 0% { bottom: 0; margin-left: -30px; width: 60px; height: 75px; background: rgba(20, 20, 20, .1); box-shadow: 0px 0 20px 35px rgba(20,20,20,.1); border-radius: 30px / 40px; -moz-animation-timing-function: ease-in; } 50% { bottom: 30px; margin-left: -10px; width: 20px; height: 5px; background: rgba(20, 20, 20, .3); box-shadow: 0px 0 20px 35px rgba(20,20,20,.3); border-radius: 20px / 20px; -moz-animation-timing-function: ease-out; } 100% { bottom: 0; margin-left: -30px; width: 60px; height: 75px; background: rgba(20, 20, 20, .1); box-shadow: 0px 0 20px 35px rgba(20,20,20,.1); border-radius: 30px / 40px; -moz-animation-timing-function: ease-in; } } @-o-keyframes shrink { 0% { bottom: 0; margin-left: -30px; width: 60px; height: 75px; background: rgba(20, 20, 20, .1); box-shadow: 0px 0 20px 35px rgba(20,20,20,.1); border-radius: 30px / 40px; -o-animation-timing-function: ease-in; } 50% { bottom: 30px; margin-left: -10px; width: 20px; height: 5px; background: rgba(20, 20, 20, .3); box-shadow: 0px 0 20px 35px rgba(20,20,20,.3); border-radius: 20px / 20px; -o-animation-timing-function: ease-out; } 100% { bottom: 0; margin-left: -30px; width: 60px; height: 75px; background: rgba(20, 20, 20, .1); box-shadow: 0px 0 20px 35px rgba(20,20,20,.1); border-radius: 30px / 40px; -o-animation-timing-function: ease-in; } } @-ms-keyframes shrink { 0% { bottom: 0; margin-left: -30px; width: 60px; height: 75px; background: rgba(20, 20, 20, .1); box-shadow: 0px 0 20px 35px rgba(20,20,20,.1); border-radius: 30px / 40px; -ms-animation-timing-function: ease-in; } 50% { bottom: 30px; margin-left: -10px; width: 20px; height: 5px; background: rgba(20, 20, 20, .3); box-shadow: 0px 0 20px 35px rgba(20,20,20,.3); border-radius: 20px / 20px; -ms-animation-timing-function: ease-out; } 100% { bottom: 0; margin-left: -30px; width: 60px; height: 75px; background: rgba(20, 20, 20, .1); box-shadow: 0px 0 20px 35px rgba(20,20,20,.1); border-radius: 30px / 40px; -ms-animation-timing-function: ease-in; } } @keyframes shrink { 0% { bottom: 0; margin-left: -30px; width: 60px; height: 75px; background: rgba(20, 20, 20, .1); box-shadow: 0px 0 20px 35px rgba(20,20,20,.1); border-radius: 30px / 40px; animation-timing-function: ease-in; } 50% { bottom: 30px; margin-left: -10px; width: 20px; height: 5px; background: rgba(20, 20, 20, .3); box-shadow: 0px 0 20px 35px rgba(20,20,20,.3); border-radius: 20px / 20px; animation-timing-function: ease-out; } 100% { bottom: 0; margin-left: -30px; width: 60px; height: 75px; background: rgba(20, 20, 20, .1); box-shadow: 0px 0 20px 35px rgba(20,20,20,.1); border-radius: 30px / 40px; animation-timing-function: ease-in; } }
/* Created by Daniel Sternlicht */ /* http://danielsternlicht.com */