css动画从上到下弹出下载按钮

html-css021

css动画从上到下弹出下载按钮,第1张

主要思路是利用hover来进行功能实现,transition-duration:来实现过度动画;

css这样实现

html如下

.download-block{

width:90%

height:100px

background:#0b0e32

/*margin:  100px  auto 0*/

    margin:0 auto

position:absolute

left:0

right:0

transition-duration:2s

opacity:0.7

}

.download-block1{

background:transparent

height:100px

overflow:hidden

position:relative

left:0

top:-100px

right:0

padding-top:100px

transition-duration:2s

opacity:0.7

cursor:pointer

}

.download-block1:hover{

padding-top:0

transition-duration:2s

opacity:0.7

}

HTML代码

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<title>用CSS3动画给一个小球创建跳跃的动画效果</title>

<link rel="stylesheet" type="text/css" href="index.css" />

</head>

<body>

<section class="main">

<div id="ballWrapper">

<div id="ball"></div>

<div id="ballShadow"></div>

</div>

</section>

</body>

</html>

CSS代码(创建一个与html同目录的index.css文件)

#ballWrapper{position:fixedtop:35%left:50%z-index:100margin-left:-70pxwidth:140pxheight:300pxcursor:pointer-webkit-transition:all 5s linear 0s-moz-transition:all 5s linear 0stransition:all 5s linear 0s-webkit-transform:scale(1)-moz-transform:scale(1)-o-transform:scale(1)transform:scale(1)-ms-transform:scale(1)}

#ballWrapper:active{cursor:pointer-webkit-transform:scale(0)-moz-transform:scale(0)-o-transform:scale(0)transform:scale(0)-ms-transform:scale(0)}

#ball{position:absolutetop:0z-index:11width:140pxheight:140pxborder-radius:70pxbackground:#bbbbackground:url(data:image/svg+xml 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%) 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 cursor: pointer base64,PD94bWwgdmVyc2lvbj0iMS4wIiA/Pgo8c3ZnIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgd2lkdGg9IjEwMCUiIGhlaWdodD0iMTAwJSIgdmlld0JveD0iMCAwIDEgMSIgcHJlc2VydmVBc3BlY3RSYXRpbz0ibm9uZSI+CiAgPGxpbmVhckdyYWRpZW50IGlkPSJncmFkLXVjZ2ctZ2VuZXJhdGVkIiBncmFkaWVudFVuaXRzPSJ1c2VyU3BhY2VPblVzZSIgeDE9IjAlIiB5MT0iMCUiIHgyPSIwJSIgeTI9IjEwMCUiPgogICAgPHN0b3Agb2Zmc2V0PSIwJSIgc3RvcC1jb2xvcj0iI2JiYmJiYiIgc3RvcC1vcGFjaXR5PSIxIi8+CiAgICA8c3RvcCBvZmZzZXQ9Ijk5JSIgc3RvcC1jb2xvcj0iIzc3Nzc3NyIgc3RvcC1vcGFjaXR5PSIxIi8+CiAgPC9saW5lYXJHcmFkaWVudD4KICA8cmVjdCB4PSIwIiB5PSIwIiB3aWR0aD0iMSIgaGVpZ2h0PSIxIiBmaWxsPSJ1cmwoI2dyYWQtdWNnZy1nZW5lcmF0ZWQpIiAvPgo8L3N2Zz4=)background:-moz-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 )-webkit-animation:jump 1s infinite-moz-animation:jump 1s infinite-o-animation:jump 1s infinite-ms-animation:jump 1s infiniteanimation:jump 1s infinite}

#ball::after{position:absolutetop:10pxleft:30pxz-index:10width:80pxheight:40pxborder-radius:40px/20pxbackground:url(data:image/svg+xml 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%) content: "" 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%)filter:progid:DXImageTransform.Microsoft.gradient( startColorstr='#e8e8e8', endColorstr='#00ffffff', GradientType=0 )}

#ballShadow{position:absolutebottom:0left:50%z-index:10margin-left:-30pxwidth:60pxheight:75pxborder-radius:30px/40pxbackground:rgba(20,20,20,.1)box-shadow:0 0 20px 35px rgba(20,20,20,.1)-webkit-transform:scaleY(.3)-moz-transform:scaleY(.3)-o-transform:scaleY(.3)transform:scaleY(.3)-ms-transform:scaleY(.3)-webkit-animation:shrink 1s infinite-moz-animation:shrink 1s infinite-o-animation:shrink 1s infinite-ms-animation:shrink 1s infiniteanimation:shrink 1s infinite}

@-webkit-keyframes jump{0%{top:0-webkit-animation-timing-function:ease-in}

50%{top:140pxheight:140px-webkit-animation-timing-function:ease-out}

55%{top:160pxheight:120pxborder-radius:70px/60px-webkit-animation-timing-function:ease-in}

65%{top:120pxheight:140pxborder-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}

50%{top:140pxheight:140px-moz-animation-timing-function:ease-out}

55%{top:160pxheight:120pxborder-radius:70px/60px-moz-animation-timing-function:ease-in}

65%{top:120pxheight:140pxborder-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}

50%{top:140pxheight:140px-o-animation-timing-function:ease-out}

55%{top:160pxheight:120pxborder-radius:70px/60px-o-animation-timing-function:ease-in}

65%{top:120pxheight:140pxborder-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}

50%{top:140pxheight:140px-ms-animation-timing-function:ease-out}

55%{top:160pxheight:120pxborder-radius:70px/60px-ms-animation-timing-function:ease-in}

65%{top:120pxheight:140pxborder-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:0animation-timing-function:ease-in}

50%{top:140pxheight:140pxanimation-timing-function:ease-out}

55%{top:160pxheight:120pxborder-radius:70px/60pxanimation-timing-function:ease-in}

65%{top:120pxheight:140pxborder-radius:70pxanimation-timing-function:ease-out}

95%{top:0animation-timing-function:ease-in}

100%{top:0animation-timing-function:ease-in}

}

@-webkit-keyframes shrink{0%{bottom:0margin-left:-30pxwidth:60pxheight:75pxborder-radius:30px/40pxbackground:rgba(20,20,20,.1)box-shadow:0 0 20px 35px rgba(20,20,20,.1)-webkit-animation-timing-function:ease-in}

50%{bottom:30pxmargin-left:-10pxwidth:20pxheight:5pxborder-radius:20pxbackground:rgba(20,20,20,.3)box-shadow:0 0 20px 35px rgba(20,20,20,.3)-webkit-animation-timing-function:ease-out}

100%{bottom:0margin-left:-30pxwidth:60pxheight:75pxborder-radius:30px/40pxbackground:rgba(20,20,20,.1)box-shadow:0 0 20px 35px rgba(20,20,20,.1)-webkit-animation-timing-function:ease-in}

}

@-moz-keyframes shrink{0%{bottom:0margin-left:-30pxwidth:60pxheight:75pxborder-radius:30px/40pxbackground:rgba(20,20,20,.1)box-shadow:0 0 20px 35px rgba(20,20,20,.1)-moz-animation-timing-function:ease-in}

50%{bottom:30pxmargin-left:-10pxwidth:20pxheight:5pxborder-radius:20pxbackground:rgba(20,20,20,.3)box-shadow:0 0 20px 35px rgba(20,20,20,.3)-moz-animation-timing-function:ease-out}

100%{bottom:0margin-left:-30pxwidth:60pxheight:75pxborder-radius:30px/40pxbackground:rgba(20,20,20,.1)box-shadow:0 0 20px 35px rgba(20,20,20,.1)-moz-animation-timing-function:ease-in}

}

@-o-keyframes shrink{0%{bottom:0margin-left:-30pxwidth:60pxheight:75pxborder-radius:30px/40pxbackground:rgba(20,20,20,.1)box-shadow:0 0 20px 35px rgba(20,20,20,.1)-o-animation-timing-function:ease-in}

50%{bottom:30pxmargin-left:-10pxwidth:20pxheight:5pxborder-radius:20pxbackground:rgba(20,20,20,.3)box-shadow:0 0 20px 35px rgba(20,20,20,.3)-o-animation-timing-function:ease-out}

100%{bottom:0margin-left:-30pxwidth:60pxheight:75pxborder-radius:30px/40pxbackground:rgba(20,20,20,.1)box-shadow:0 0 20px 35px rgba(20,20,20,.1)-o-animation-timing-function:ease-in}

}

@-ms-keyframes shrink{0%{bottom:0margin-left:-30pxwidth:60pxheight:75pxborder-radius:30px/40pxbackground:rgba(20,20,20,.1)box-shadow:0 0 20px 35px rgba(20,20,20,.1)-ms-animation-timing-function:ease-in}

50%{bottom:30pxmargin-left:-10pxwidth:20pxheight:5pxborder-radius:20pxbackground:rgba(20,20,20,.3)box-shadow:0 0 20px 35px rgba(20,20,20,.3)-ms-animation-timing-function:ease-out}

100%{bottom:0margin-left:-30pxwidth:60pxheight:75pxborder-radius:30px/40pxbackground:rgba(20,20,20,.1)box-shadow:0 0 20px 35px rgba(20,20,20,.1)-ms-animation-timing-function:ease-in}

}

@keyframes shrink{0%{bottom:0margin-left:-30pxwidth:60pxheight:75pxborder-radius:30px/40pxbackground:rgba(20,20,20,.1)box-shadow:0 0 20px 35px rgba(20,20,20,.1)animation-timing-function:ease-in}

50%{bottom:30pxmargin-left:-10pxwidth:20pxheight:5pxborder-radius:20pxbackground:rgba(20,20,20,.3)box-shadow:0 0 20px 35px rgba(20,20,20,.3)animation-timing-function:ease-out}

100%{bottom:0margin-left:-30pxwidth:60pxheight:75pxborder-radius:30px/40pxbackground:rgba(20,20,20,.1)box-shadow:0 0 20px 35px rgba(20,20,20,.1)animation-timing-function:ease-in}

}

在 CSS3 出现之前,动画都是通过 JavaScript 动态的改变元素的样式属性来完成了,这种方式虽然能够实现动画,但是在性能上存在一些问题。CSS3 的出现,让动画变得更加容易,性能也更加好。

CSS3 中有三个关于动画的样式属性 transform 、 transition 和 animation ;

transform 可以用来设置元素的形状改变,主要有以下几种变形: rotate (旋转)、 scale (缩放)、 skew (扭曲)、 translate (移动)和 matrix (矩阵变形),语法如下:

none 表示不做变换; <transform-function>表示一个或多个变化函数,变化函数由函数名和参数组成,参数包含在 () 里面,用 空格 分开,例如:

所有的变形都是基于基点,基点默认为元素的中心点。用法: transform-origin: (x, y) ,其中 x 和 y 的值可以是百分比、rem 或者是 px 等等,也可以用表示位置的单词来表示例如:x 可以用 left 、 center 、 right ;y 可以用 top 、 center 、 bottom 。

用法: rotate(<angle>) ;表示通过指定的角度对元素进行旋转变形,如果是正数则顺时针旋转,如果是负数则逆时针旋转,例如:

它有三种用法: scale(<number>[, <number>]) 、 scaleX(<number>) 和 scaleY(<number>) ;分别代表水平和垂直方向同时缩放、水平方向的缩放以及垂直方向的缩放,入参代表水平或者垂直方向的缩放比例。缩放比例如果大于1则放大,反之则缩小,如果等于1代表原始大小。

移动也分三种情况: translate(<translation-value>[, <translation-value>]) 、 translateX(<translation-value>) 和 translateY(<translation-value>) ;分别代表水平和垂直的移动、水平方向的移动以及垂直方向同时移动,移动单位是 CSS 中的长度单位: px 、 rem 等

扭曲同样也有三种情况, skew(<angle>[, <angle>]) 、 skewX(<angle>) 和 skewY(<angle>) ;同样也是水平和垂直方向同时扭曲、水平方向的扭曲以及垂直方向的扭曲,单位为角度。

矩阵变形相对来说非常复杂,涉及到数学中的矩阵计算,有兴趣的同学可以研究一下: CSS3 Transform Matrix

transition 是用来设置样式的属性值是如何从从一种状态变平滑过渡到另外一种状态,它有四个属性:

它是用来设置哪些属性的改变会有这种平滑过渡的效果,主要有以下值:

它是用来设置转换过程的持续时间,单位是 s 或者 ms ,默认值为0;

它是来设置过渡效果的速率,它有6种形式的速率:

它是来设置过渡动画开始执行的时间,单位是 s 或者 ms ,默认值为0;

它是 transition-property 、 transition-duration 、 transition-timing-function 、 transition-delay 的简写:

animation 比较类似于 flash 中的 逐帧动画 ,逐帧动画就像电影的播放一样,表现非常细腻并且有非常大的灵活性。然而 transition 只是指定了开始和结束态,整个动画的过程也是由特定的函数控制。学习过 flash 的同学知道,这种逐帧动画是由 关键帧 组成,很多个关键帧连续的播放就组成了动画,在 CSS3 中是由属性 keyframes 来完成逐帧动画的。

它是用来设置动画的名称,可以同时赋值多个动画名称,用 , 隔开:

它是用来设置动画的持续时间,单位为 s ,默认值为 0 :

和 transition-timing-function 类似:

它是来设置动画的开始时间,单位是 s 或者 ms ,默认值为0:

它是来设置动画循环的次数,默认为 1 , infinite 为无限次数的循环:

它是来设置动画播放的方向,默认值为 normal 表示向前播放, alternate 代表动画播放在第偶数次向前播放,第奇数次向反方向播放:

它主要是来控制动画的播放状态: running 代表播放,而 paused 代表停止播放, running 为默认值:

它是 animation-name 、 animation-duration 、 animation-timing-function 、 animation-delay 、 animation-iteration-count 、 animation-direction 的简写:

关于 CSS3 的动画的三个属性 transform 、 transition 、 animation 我们都介绍完了,让我们回顾一下。 transform 我们可以理解为元素的几何变形,它是有规律可寻的,这种变形并不会产生动画效果仅仅是原有形状的改变; transition 和 animation 它们很像 flash 中的 补间动画 逐帧动画 ; transition 是从一个状态变化到另外一种状态,当变化有了平滑的效果后就产生了动画,它是一个公式化的变化,在比较规则的动画效果中我们可以使用,例如:旋转的风车、行驶的汽车、颜色的渐变等等; animation 的动画效果更加灵活,可以实现像影片一样的复杂无规则的动画。