gsap+css实现炫酷全屏图片点击交互轮换代码
代码语言:html
所属分类:幻灯片
代码描述:gsap+css实现炫酷全屏图片点击交互轮换代码
代码标签: gsap css 炫酷 全屏 图片 点击 交互 轮换 代码
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html> <html lang="en" > <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link type="text/css" rel="stylesheet" href="//repo.bfw.wiki/bfwrepo/css/reset.min.css"> <style> html, body { margin:0; padding:0; } body { overflow: hidden; } #container { height: 100vh; overflow-y: auto; -webkit-overflow-scrolling: touch; } svg { position:fixed; } </style> </head> <body> <div id="container"> <svg width="100%" height="100%"> <mask id="m"> <circle id="c1" cx="40" cy="40" r="0" fill="#fff"/> <circle id="c0" cx="40" cy="40" r="0" fill="#fff" opacity="0.5"/> </mask> <g id="imgFg"></g> <g id="imgBg" mask="url(#m)"></g> </svg> </div> <script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/gsap.3.11.0.js"></script> <script > console.clear() const stage = document.querySelector('svg') const imgFg = document.querySelector('#imgFg') const imgBg = document.querySelector('#imgBg') const imgs = [ '//repo.bfw.wiki/bfwrepo/image/639a9910e411e.png', '//repo.bfw.wiki/bfwrepo/image/639a98f6e8b32.png', '//repo.bfw.wiki/bfwrepo/image/639a98d5110dd.png', '//repo.bfw.wiki/bfwrepo/image/639a98b981099.png', '//repo.bfw.wiki/bfwrepo/image/638b0cf2a3174.png' ] const pos = {x:innerWidth/2, y:innerHeight/2} for (let i=0; i<imgs.length; i++){ const img = document.createElementNS("http://www.w3.org/2000/svg", "image") imgBg.appendChild(img) gsap.set(img, {attr:{x:'-5%', y:'-5%', width:'110%', height:'110%', href:imgs[i], preserveAspectRatio:'xMidYMid slice'}}) } window.addEventListener('resize', ()=>{ pos.x = innerWidth/2 pos.y = innerHeight/2 gsap.set('circle', {duration:0.3, attr:{cx:pos.x, cy:pos.y}}) .........完整代码请登录后点击上方下载按钮下载查看
网友评论0