{
    分享网正式开通,我们为大家提供免费资源,欢迎大家踊跃投稿!

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>


在线预览
资源均来自第三方,谨慎下载,前往第三方网站下载


爱资源分享网 , 版权所有丨本站资源仅限于学习研究,严禁从事商业或者非法活动!丨本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:jQuery+css3橙汁汽泡动画特效
喜欢 ()分享 (0)