Files
ClassContent/历届学生/font-end-nine/项目练习/学生项目/张婷/作业/水管鸟/js/util.js
2024-09-27 02:06:13 +08:00

57 lines
1.6 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

class Util{
$(className) {
if (document.querySelectorAll(className).length > 1) {
return document.querySelectorAll(className)
} else {
return document.querySelector(className)
}
}
click(className,callback) {
$(className).onclick = () => {
callback()
}
}
inject() {
Element.prototype.remove = function (removeClassName) {
this.classList.remove(removeClassName);
}
Element.prototype.add = function (addClassName) {
this.classList.add(addClassName);
}
}
}
var { $, click, inject } = new Util()
inject()
//定义两个变量存放创建的上水管和下水管
// var TopWaterPipe = cretedImg("top")
// var BottomWaterPipe = cretedImg("bottom")
//添加上水管以及下水管
// $("body").appendChild(TopWaterPipe)
// $("body").appendChild(BottomWaterPipe)
// this.WaterPipeMove(TopWaterPipe)
// this.WaterPipeMove(BottomWaterPipe)
//水管运动
// WaterPipeMove(img) {
// img.time = setInterval(() => {
// img.style.left = `${parseInt(img.style.left) - this.groundSpeed}px`
// // 让水管每次移动距离为当前的x轴距离减去地板移动的速度(保证水管和地板是同时运动的)
// if (parseInt(img.style.left) <= -55) {
// clearInterval(img.time)
// $("body").removeChild(img)
// // 如果水管的x轴距离小于他本身时 也就是全部移除屏幕时 删除定时器以及元素
// }
// }, 1000 / 16)
// }