小球弹跳纯matlab,小球的弹跳效果

body {

margin: 0;

padding: 0;

}

#ball {

background: red;

height: 100px;

width: 100px;

position: absolute;

top: 10px;

left: 20px;

border-radius: 50px;

background-image: -webkit-gradient(radial, 30px 30px, 0, 30px 30px, 100, color-stop(1%, #ffe0dd), color-stop(5%, #ff3019), color-stop(54%, #d60404), color-stop(100%, #4f0101));

background-image: -webkit-radial-gradient(30px 30px, ellipse cover, #ffe0dd 1%, #ff3019 5%, #d60404 54%, #4f0101 100%);

background-image: -moz-radial-gradient(30px 30px, ellipse cover, #ffe0dd 1%, #ff3019 5%, #d60404 54%, #4f0101 100%);

background-image: -o-radial-gradient(30px 30px, ellipse cover, #ffe0dd 1%, #ff3019 5%, #d60404 54%, #4f0101 100%);

background-image: radial-gradient(30px 30px, ellipse cover, #ffe0dd 1%, #ff3019 5%, #d60404 54%, #4f0101 100%);

}

#floor {

position: absolute;

bottom: 10px;

left: 0px;

width: 350px;

height: 1px;

border-top: 5px solid brown;

}

bounce

(function(){

var down = false,

trans = 'transition';

eventName = 'transitionend';

//use prefix if necessary

if(typeof document.body.style.webkitTransition === 'string') {

trans = 'webkitTransition';

eventName = 'webkitTransitionEnd';

} else if (typeof document.body.style.MozTransition === 'string') {

trans = 'MozTransition';

}

var ball = document.getElementById('ball'),

floor = document.getElementById('floor');

ball.style.top = (floor.offsetTop - 100) + 'px';

function bounce() {

if(down) {

ball.style[trans] = "top 1s cubic-bezier(0, .27, .32, 1)";

// ball.style[trans] = "top 1s ease-out";

ball.style.top = '10px';

down = false;

} else {

ball.style[trans] = "top 1s cubic-bezier(1, 0, 0.96, 0.91)";

// ball.style[trans] = "top 1s ease-in";

ball.style.top = (floor.offsetTop - 100) + 'px';

down = true;

}

}

ball.addEventListener(eventName, bounce);

bounce();

})();

a0aa56379c79

Paste_Image.png

2.用transform,translate实现,用了

bounce

body {

margin: 0;

padding: 0;

}

#ball {

background: red;

height: 100px;

width: 100px;

position: absolute;

top: 10px;

left: 20px;

border-radius: 50px;

background-image: -webkit-gradient(radial, 30px 30px, 0, 30px 30px, 100, color-stop(1%, #ffe0dd), color-stop(5%, #ff3019), color-stop(54%, #d60404), color-stop(100%, #4f0101));

background-image: -webkit-radial-gradient(30px 30px, ellipse cover, #ffe0dd 1%, #ff3019 5%, #d60404 54%, #4f0101 100%);

background-image: -moz-radial-gradient(30px 30px, ellipse cover, #ffe0dd 1%, #ff3019 5%, #d60404 54%, #4f0101 100%);

background-image: -o-radial-gradient(30px 30px, ellipse cover, #ffe0dd 1%, #ff3019 5%, #d60404 54%, #4f0101 100%);

background-image: radial-gradient(30px 30px, ellipse cover, #ffe0dd 1%, #ff3019 5%, #d60404 54%, #4f0101 100%);

}

#floor {

position: absolute;

bottom: 10px;

left: 0px;

width: 350px;

height: 1px;

border-top: 5px solid brown;

}

/* WebKit */

@-webkit-keyframes bounce {

0% {

-webkit-transform: translate3d(0, 20px, 0);

-webkit-animation-timing-function: cubic-bezier(1, 0, 0.96, 0.91);

}

50% {

-webkit-transform: translate3d(0, 300px, 0);

-webkit-animation-timing-function: cubic-bezier(0, 0.27, 0.32, 1);

}

100% {

-webkit-transform: translate3d(0, 20px, 0);

-webkit-animation-timing-function: cubic-bezier(0, 0.27, 0.32, 1);

}

}

/* Firefox < 16*/

@-moz-keyframes bounce {

0% {

-moz-transform: translate3d(0, 20px, 0);

-moz-animation-timing-function: cubic-bezier(1, 0, 0.96, 0.91);

}

50% {

-moz-transform: translate3d(0, 300px, 0);

-moz-animation-timing-function: cubic-bezier(0, 0.27, 0.32, 1);

}

100% {

-moz-transform: translate3d(0, 20px, 0);

-moz-animation-timing-function: cubic-bezier(0, 0.27, 0.32, 1);

}

}

/* Opera < 12.1*/

@-o-keyframes bounce {

0% {

-o-transform: translate3d(0, 20px, 0);

-o-animation-timing-function: cubic-bezier(1, 0, 0.96, 0.91);

}

50% {

-o-transform: translate3d(0, 300px, 0);

-o-animation-timing-function: cubic-bezier(0, 0.27, 0.32, 1);

}

100% {

-o-transform: translate3d(0, 20px, 0);

-o-animation-timing-function: cubic-bezier(0, 0.27, 0.32, 1);

}

}

/* W3C / IE10 / Firefox / opera */

@keyframes bounce {

0% {

transform: translate3d(0, 20px, 0);

animation-timing-function: cubic-bezier(1, 0, 0.96, 0.91);

}

50% {

transform: translate3d(0, 300px, 0);

animation-timing-function: cubic-bezier(0, 0.27, 0.32, 1);

}

100% {

transform: translate3d(0, 20px, 0);

animation-timing-function: cubic-bezier(0, 0.27, 0.32, 1);

}

}

#holder {

position: absolute;

height: 100%;

width: 100%;

background: url(http://farm9.staticflickr.com/8175/8065409112_2b4b5e16c4_k.jpg);

}

#floor {

top: 400px;

}

#ball {

-webkit-animation: 2s bounce infinite;

-moz-animation: 2s bounce infinite;

-ms-animation: 2s bounce infinite;

-o-animation: 2s bounce infinite;

animation-duration: 2s;

animation-name: bounce;

animation-iteration-count: infinite;

animation-timing-function: linear;

}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值