css3模拟窗口抖动,jQuery模拟窗口抖动效果

效果图:

21e7175e07a4ccd782dcbb645ee3c0e1.png

代码如下:

jQuery模拟窗口抖动

input{margin-top: 20px;}

.center{margin-left: 50%;transform: translate(-50%);}

.img{display:block;position:absolute;top:100px;}

02c26edec76e5a6ff580f514dbad07bd.png

$(":button").click(function () {

var len = 4, //晃动的距离,单位像素

c = 16, //晃动次数,4次一圈

step = 0, //计数器

img = $("img"),

off = img.offset();

this.step = 0;

timer = setInterval(function () {

var set = pos();

img.offset({ top: off.top + set.y * len, left: off.left + set.x * len });

if (step++ >= c) {

img.offset({ top: off.top, left: off.left }); //抖动结束回归原位

clearInterval(timer);

}

// console.log(step)

}, 45);

});

function pos() {

this.step = this.step ? this.step : 0;

this.step = this.step == 4 ? 0 : this.step;

var set = {

0: { x: 0, y: -1 },

1: { x: -1, y: 0 },

2: { x: 0, y: 1 },

3: { x: 1, y: 0 }

}

return set[this.step++];

}

以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,同时也希望多多支持脚本之家!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要实现 CSS 元素的 3D 抖动效果,可以使用 CSS3 的动画和 transform 属性,具体步骤如下: 1. 首先,需要将元素设置为 3D 空间,可以通过设置 perspective 属性实现: ```css .container { perspective: 1000px; } ``` 2. 接着,使用 CSS3 的动画和 transform 属性来实现抖动效果: ```css @keyframes shake { 0% { transform: translate3d(0, 0, 0) rotate3d(0, 0, 0, 0); } 10% { transform: translate3d(-10px, 0, 0) rotate3d(0, 0, 1, -5deg); } 20% { transform: translate3d(10px, 0, 0) rotate3d(0, 0, 1, 5deg); } 30% { transform: translate3d(-10px, 0, 0) rotate3d(0, 0, 1, -5deg); } 40% { transform: translate3d(10px, 0, 0) rotate3d(0, 0, 1, 5deg); } 50% { transform: translate3d(-10px, 0, 0) rotate3d(0, 0, 1, -5deg); } 60% { transform: translate3d(10px, 0, 0) rotate3d(0, 0, 1, 5deg); } 70% { transform: translate3d(-10px, 0, 0) rotate3d(0, 0, 1, -5deg); } 80% { transform: translate3d(10px, 0, 0) rotate3d(0, 0, 1, 5deg); } 90% { transform: translate3d(-10px, 0, 0) rotate3d(0, 0, 1, -5deg); } 100% { transform: translate3d(0, 0, 0) rotate3d(0, 0, 0, 0); } } .element { animation: shake 0.8s; animation-iteration-count: infinite; } ``` 这段代码中,我们定义了一个名为 shake 的动画,它包含多个关键帧,每个关键帧都使用 translate3d 和 rotate3d 方法来实现元素的平移和旋转。然后,将这个动画应用到需要抖动的元素上,使用 animation-iteration-count 属性来让动画无限循环。 这样,就可以实现 CSS 元素的 3D 抖动效果了。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值