代码拉取完成,页面将自动刷新
const electron = require('@electron/remote')
const workAreaSize = electron.screen.getPrimaryDisplay().workAreaSize
class Flower {
constructor(url) {
this._img = document.createElement('img')
this._img.src = `img/flower/${url}`
this._img.width = Math.random() * 40 + 5
this.x = 100
this.y = 80
this.rotaion = 0
this.speedX = (Math.random()*6 + 5)
this.speedY = (Math.random()*6 + 9)
this.speedRotation = (Math.random() + 1) * (Math.random() > 0.5 ? 1 : -1)
this.move()
}
get img() {
return this._img;
}
move() {
this.speedX = (this.speedX - 0.1) > 1 ? (this.speedX - 0.1): this.speedX
this.x += this.speedX
this.speedY = (this.speedY - 0.3) > 1 ? (this.speedY - 0.5) :this.speedY
if (this.x > (workAreaSize.width/4)) {
this.speedY = -(Math.random()*2)
}
this.y += this.speedY
this.rotaion += this.speedRotation
this.img.style.transform = `translate(-${this.x}px, -${this.y}px) rotate(${this.rotaion}deg)`
if (this.y <= 50 || Math.abs(this.x+50) >= (workAreaSize.width*0.5) || Math.abs(this.y+50) >= (workAreaSize.height*0.5)) {
if (this._img.parentNode) {
this._img.parentNode.removeChild(this._img)
}
}else {
// 以屏幕刷新频率执行
requestAnimationFrame(() => {
this.move()
})
}
}
}
module.exports = Flower;
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。