jQuery+css3橙汁汽泡动画特效

jQuery+css3橙汁汽泡动画特效-精品资源网
jQuery+css3橙汁汽泡动画特效
此内容为免费资源,请登录后查看
0
免费资源

jQuery+css3橙汁汽泡动画特效

一款非常好看的jQuery+css3橙汁汽泡动画特效,类似橙汁里面的气泡浮动动画效果,把背景换成蓝色,就成了大海里的汽泡了。

js代码

<script>
const floatOn = options => {
	let el = options.el,
		x = options.x,
		xIsPos = options.xIsPos || Math.floor(Math.random()),
		updateX = options.updateX || Math.floor(Math.random()),
		curTop = parseInt(el.style.top),
		curLeft = parseInt(el.style.left);

	if (curTop > -50) {
		el.style.top = `${--curTop}px`;
	} else {
		el.style.top = `${innerHeight + 50}px`;
	}

	if (updateX) {
		if (xIsPos) {
			if (curLeft > x + 10) {
				xIsPos = false;
			} else {
				el.style.left = `${curLeft + 1}px`;
			}
		} else {
			if (curLeft < x - 10) {
				xIsPos = true;
			} else {
				el.style.left = `${--curLeft}px`;
			}
		}
	}

	updateX = updateX ? false : true;

	requestAnimationFrame(
		floatOn.bind(null, { el: el, x: x, xIsPos: xIsPos, updateX: updateX })
	);
};

class Bubble {
	constructor(target, i) {
		this.bubble = document.createElement(\"div\");
		this.bubble.classList.add(\"bubble\");
		this.x = Math.floor(Math.random() * innerWidth);
		this.y = Math.floor(Math.random() * innerHeight);
		this.scale = Math.random();
		this.pos = Math.round(Math.random());

		this.bubble.style.top = `${this.y}px`;
		this.bubble.style.left = `${this.x}px`;
		this.bubble.style.transform = `translateZ(${
			this.pos ? \"\" : \"-\"
		}${this.scale.toFixed(2) * 1000}px)`;

		setTimeout(() => {
			target.appendChild(this.bubble);
		}, i * 50);
		setTimeout(floatOn.bind(null, { el: this.bubble, x: this.x }), i * 50);
	}
}

for (let i = 0; i < 100; i++) {
	new Bubble(document.querySelector(\".soda\"), i);
}
</script>

© 版权声明
THE END
点赞0 分享
评论 抢沙发
头像
欢迎您留下宝贵的见解!
提交
头像

昵称

取消
昵称表情代码图片

    暂无评论内容