html怎么做一张抖动的图片,纯CSS实现图片抖动

实现方法:

1.将上文提到的以下JS内容删除:

$(".imagelogo").mouseover(function() {

obj = $(this);

i = 5;

timer = null;

clearInterval(timer);

timer = setInterval(function(){

obj.css({"position":"relative","left":i+"px"});

i = -i;

},50);

});

$(".imagelogo").mouseout(function() {

clearInterval(timer);

});

2.在CSS样式里加上以下内容:

@keyframes mylogo

{

from {left: 5px;}

to {left: -5px;}

}

@-moz-keyframes mylogo /* Firefox */

{

from {left: 5px;}

to {left: -5px;}

}

@-webkit-keyframes mylogo /* Safari 和 Chrome */

{

from {left: 5px;}

to {left: -5px;}

}

@-o-keyframes mylogo /* Opera */

{

from {left: 5px;}

to {left: -5px;}

}

.imagelogo {

background: url(images/logo.png) no-repeat;

float: left;

position:relative;

width: 180px;

height: 60px;

margin: 15px 0px 0px 0px;

padding: 0px;

cursor: pointer;

animation: mylogo 1s linear 0s infinite alternate;

/* Firefox: */

-moz-animation: mylogo 1s linear 0s infinite alternate;

/* Safari 和 Chrome: */

-webkit-animation: mylogo 1s linear 0s infinite alternate;

/* Opera: */

-o-animation: mylogo 1s linear 0s infinite alternate;

}

好了,有点像钟摆的样子了,上文的animation: mylogo 1s linear 0s infinite alternate是简写,展开后就是:

animation-name: mylogo ;

animation-duration: 1s;

animation-timing-function: linear;

animation-delay: 0s;

animation-iteration-count: infinite;

animation-direction: alternate;

原文:http://www.cnblogs.com/freespider/p/5358159.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
实现图片在顶部固定的情况下,立体上下抖动的效果,可以使用CSS的animation属性和transform属性。 首先需要将图片包含在一个div中,并设置该div的position属性为relative,以便在之后设置子元素的绝对定位。 然后,使用伪元素:before来创建一个元素,作为抖动效果的背景。 接下来,使用transform属性来设置图片的位置和大小,并使用animation属性来设置动画效果,使其看起来像是图片在上下抖动。 下面是一个简单的示例代码: HTML代码: ``` <div class="shake"> <img src="your_image_url" alt="your_image_alt"> </div> ``` CSS代码: ``` .shake { position: relative; overflow: hidden; } .shake::before { content: ""; position: absolute; top: 0; left: 0; width: 100%; height: 100%; background-color: #fff; transform: translateZ(-1px); } .shake img { position: absolute; top: 0; left: 50%; transform: translateX(-50%) translateY(0); } .shake:hover img { animation: shake 0.5s ease-in-out infinite; } @keyframes shake { 0% { transform: translateX(-50%) translateY(0) translateZ(0); } 25% { transform: translateX(-50%) translateY(-3px) translateZ(-3px); } 50% { transform: translateX(-50%) translateY(0) translateZ(0); } 75% { transform: translateX(-50%) translateY(3px) translateZ(-3px); } 100% { transform: translateX(-50%) translateY(0) translateZ(0); } } ``` 在这个示例中,当鼠标悬停在图片上时,图片将开始抖动。你可以根据自己的需求来调整元素的大小、位置和动画效果,以达到你想要的立体上下抖动的效果。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值