JS如何实现polyfill.io主页上的这个效果?
javascript吧
全部回复
仅看楼主
level 7
就是鼠标箭头移动到任意一个蓝色柱状下,柱子下端就会延长至图片底部,然后返回缩小长度直到恢复原状?
2023年10月05日 00点10分 1
level 8
查看网页源码
2023年10月05日 02点10分 2
level 13
polyfill.io的这个效果不是用 js 实现的,人家是用 svg animate 动画做的
2023年10月05日 03点10分 3
level 1
没看网站 你说的这个csshover就能实现
2023年11月01日 00点11分 4
hover具体怎么实现?
2023年11月01日 04点11分
level 11
<!DOCTYPE html><html>
<head> <meta nane="description" content="imitate anime of polyfill.io"/> <meta name="keywords" content="polyfill.io,imitate,anime"/> <meta charset="UTF-8"/> <title>模拟蓝条动画</title> </head> <body id="bodyDom"> <script> const szWidth = 32; const szHeight = 760;
const mvSpeed = 13;
const fps = 60;
const clrBack = "#FFFFFF"; const clrLine = "#66CCFF";
const countLines = 50;
class PolyLine { constructor(height) { this.height = (height>=0) ? height : Math.floor(Math.random()*szHeight); this.nowHeight = height; this.direction = "up"; } update() { if (this.direction == "up") { this.nowHeight -= mvSpeed; if (this.nowHeight < this.height) { this.nowHeight = this.height; } } else { this.nowHeight += mvSpeed; if (this.nowHeight > szHeight) { this.direction = "up"; } } } draw(context) { context.fillStyle = clrBack; context.fillRect(0, 0, szWidth, szHeight); context.fillStyle = clrLine; context.fillRect(0, 0, szWidth, this.nowHeight); context.strokeStyle = "black"; context.strokeRect(0, 0, szWidth, this.nowHeight); }
move(dir) { this.direction = dir; } }
var bodyDom = document.getElementById("bodyDom"); var polyLines = [];
for (let i=0; i!=countLines; ++i) { polyLines.push(new PolyLine(-1)); bodyDom.innerHTML += "<canvas id='"+i+"' onmouseover='mouseOver(this.id)' onmouseout='mouseOut(this.id)'></canvas>"; let canv = document.getElementById(i); canv.width = szWidth; canv.height = szHeight; canv.style.display = "inline"; }
function mouseOver(id) { polyLines[id].move("down"); }
function mouseOut(id) { polyLines[id].move("up"); }
function frameUpdate() { var dom = document; for (let p in polyLines) { polyLines[p].update(); let context = dom.getElementById(p).getContext("2d"); polyLines[p].draw(context); } }
setInterval(frameUpdate, 1000/fps); </script> </body> </html>
2023年11月15日 06点11分 6
这是删除注释版的,不用整理格式也能直接运行
2023年11月15日 06点11分
[真棒]
2023年11月15日 09点11分
level 6
我的思路就是获取鼠标坐标,用数组表示蓝色x区间,在用action或者计时器增加蓝色y值,然后判断,具体没电脑,不好验证
2023年11月28日 02点11分 7
1