Toggle navigation
在线编辑器
在线代码
文本比较
jQuery下载
前端库
在线手册
登录/注册
下载代码
html
css
js
分享到微信朋友圈
X
html
Bubbles
Click bubble to burst it!
css
@import "https://fonts.googleapis.com/css?family=Mouse+Memoirs"; HTML, BODY { height: 100%; } BODY { background-color: lightyellow; background: radial-gradient(lightyellow, gold, teal, indigo); } .hidden { display: none; } .marked { outline: 2px solid red; stroke: red; stroke-width: 2; } .svg { position: absolute; width: 250px; height: 250px; overflow: visible; mix-blend-mode: multiply; } .svg--defs { width: 0; height: 0; } .demo { position: absolute; top: 0; right: 0; bottom: 0; left: 0; overflow: hidden; isolation: isolate; } .demo__title { position: absolute; right: 1rem; bottom: 1rem; text-shadow: 0 0 15px rgba(0, 0, 0, 0.5); font-family: 'Mouse Memoirs', sans-serif; font-size: 4.9rem; color: #FFF; cursor: pointer; } .demo-title__splash { position: absolute; top: -75px; left: -40px; opacity: 0; pointer-events: none; } .demo__tip { display: block; font-size: 1rem; font-family: Trebuchet MS; } .bubble { cursor: pointer; } .bubble__splash { opacity: 0; pointer-events: none; }
JavaScript
'use strict'; console.clear(); var maxBubbles = 25; //25 var container = document.querySelector('.demo'); var containerWidth = container.clientWidth; var containerHeight = container.clientHeight; var content = document.querySelector('.demo__content'); var title = document.querySelector('.demo__title'); title.content = document.querySelector('.demo-title__content'); title.splash = document.querySelector('.demo-title__splash'); var shape = document.querySelector('.bubble'); var shapeWidth = shape.clientWidth; var shapeHeight = shape.clientHeight; var bubbles = []; var minX = 0; var minY = 0; var baseShapeSize = 200; var minShapeSize = 50; var time = 7; var minTime = 4; var posibleSides = ['top', 'right', 'bottom', 'left']; //------------------------------ function Bubble( pos ) { this.bubble = shape.cloneNode( true ); this.setSize(); this.setPos(); this.addAnimation(); content.appendChild( this.bubble ); this.content = this.bubble.querySelector('.bubble__group'); this.splash = this.bubble.querySelector('.bubble__splash'); this.isCollapsed = false; var that = this; this.bubble.onclick = function () { if ( !that.isCollapsed ) { that.isCollapsed = true; that.collapse(); } } } //------------------------------ Bubble.prototype.collapse = function () { var that = this; function resetBubble() { var tl = new TimelineLite(); that.setSize(); that.setPos(); tl.to( that.content, .3, { 'scale': 1, 'opacity': 1, 'delay': 2, 'onComplete': function() { that.isCollapsed = false; } } ); } var tl = new TimelineLite(); tl.set( this.content, { 'scale': 0, 'transform-origin': '100px 100px', 'opacity': 0 } ); tl.set( this.splash, { 'scale': .5, 'transform-origin': '100px 100px', 'opacity': 1, } ); tl.to( this.splash, .15, { 'scale': 1.5, 'opacity': 0, 'ease': Power1.easeOut, 'onComplete': resetBubble } ); } //------------------------------ Bubble.prototype.setPos = function () { var target = this.getSide(); this.bubble.style.transform = 'translate3d(' + target.coords.x +'px, ' + target.coords.y + 'px, 0)'; } //------------------------------ Bubble.prototype.setSize = function () { this.shapeSize = Math.round( Math.random() * (baseShapeSize - minShapeSize) ) + minShapeSize; this.bubble.style.width = this.shapeSize + 'px'; this.bubble.style.height = this.shapeSize + 'px'; this.maxX = containerWidth - this.shapeSize; this.maxY = containerHeight - this.shapeSize; } //------------------------------ Bubble.prototype.addAnimation = function () { var minX = 0; var newTime = Math.random() * time + minTime; var elem = this.bubble; var delay = Math.random() * time; var tl = new TimelineLite(); var that = this; animate(); function animate () { var target = that.getSide( that.side ); that.side = target.side; var propSet = { x: target.coords.x, y: target.coords.y, ease: SlowMo.easeInOut, delay: delay, onComplete: animate }; tl.to( elem, newTime, propSet); if ( delay ) { delay = 0; } } } //------------------------------ Bubble.prototype.getSide = function () { var targetParams = { side: '', coords: {} }; var maxRandX = Math.round( Math.random() * this.maxX ); var maxRandY = Math.round( Math.random() * this.maxY ); var sides = {'top': { x: maxRandX, y: minY }, 'right': { x: this.maxX, y: maxRandY }, 'bottom': { x: maxRandX, y: this.maxY }, 'left': { x: minX, y: maxRandY } }; delete sides[ this.side ]; var keys = Object.keys( sides ); var randPos = Math.floor( Math.random() * keys.length ); var newSide = keys[ randPos ]; targetParams.side = newSide; targetParams.coords = sides[ newSide ]; return targetParams; } //------------------------------ function addBubble () { var bubble = new Bubble( i ); bubbles.push( bubble ); } //------------------------------ for ( var i = 0; i < maxBubbles; i ++ ) { addBubble(); } //------------------------------ window.onresize = function () { containerWidth = container.clientWidth; containerHeight = container.clientHeight; bubbles.forEach( function ( item ) { item.maxX = containerWidth - item.shapeSize; item.maxY = containerHeight - item.shapeSize; // item.addAnimation(); }); } //------------------------------ title.onclick = function () { var that = this; function resetElem() { var tl = new TimelineLite(); tl.to( that.content, .3, { 'scale': 1, 'opacity': 1, 'onComplete': function() { that.isCollapsed = false; } } ); } var tl = new TimelineLite(); tl.set( this.content, { 'scale': 0, 'opacity': 0 } ); tl.set( this.splash, { 'scale': .5, 'opacity': 1, } ); tl.to( this.splash, .15, { 'scale': 1.5, 'opacity': 0, 'ease': Power1.easeOut, 'onComplete': resetElem } ); }
粒子
时间
文字
hover
canvas
3d
游戏
音乐
火焰
水波
轮播图
鼠标跟随
动画
css
加载动画
导航
菜单
按钮
滑块
tab
弹出层
统计图
svg
×
Close
在线代码下载提示
开通在线代码永久免费下载,需支付20jQ币
开通后,在线代码模块中所有代码可终身免费下!
您已开通在线代码永久免费下载,关闭提示框后,点下载代码可直接下载!
您已经开通过在线代码永久免费下载
对不起,您的jQ币不足!可通过发布资源 或
直接充值获取jQ币
取消
开通下载
<!doctype html> <html> <head> <meta charset="utf-8"> <title>SVG 气泡-jq22.com</title> <script src="https://www.jq22.com/jquery/jquery-1.10.2.js"></script> <style>
</style> </head> <body>
<script>
</script>
</body> </html>
2012-2021 jQuery插件库版权所有
jquery插件
|
jq22工具库
|
网页技术
|
广告合作
|
在线反馈
|
版权声明
沪ICP备13043785号-1
浙公网安备 33041102000314号