面试题第一期

发布于:2023-05-30 ⋅ 阅读:(233) ⋅ 点赞:(0)

1.如何让3个元素的四个间距平分盒子
justify-content: space-evenly;

space-between:两端对齐,项目之间的间隔是相等的(n-1个间隔)
space-evenly:均匀排列每个元素,每个元素之间的间隔相等(n+1)

第二种:
margin-left:calc((100%-4*元素宽度)/4)

2.promise.all 特性是一个报错就停止 怎么让一个报错后拿到其他的数据

Promise.allSettled() 方法是 promise 并发性方法的其中之一。在你有多个不依赖于彼此成功完成的异步任务时,或者你总是想知道每个 promise 的结果时,使用 Promise.allSettled() 。

相比之下,如果任务相互依赖,或者如果你想立即拒绝其中任何任务,Promise.all() 返回的

3.写一个弹窗拖拽的功能

1.按下鼠标时触发onmousedown事件,获取元素位置(diffX=e.clientX - drag.offsetLeft)
2.移动时触发onmousemove事件,设置边界值(e.clientX - diffX)
3.抬起鼠标时onmouseup(this.onmousemove = null this.onmouseup = null)

window.onload = function() {
    //获取drag元素
    let drag = document.getElementById("drag")
    //当鼠标按下时
    drag.onmousedown = function(e) {
        //做到浏览器兼容
        e = e || window.event
        let diffX = e.clientX - drag.offsetLeft
        let diffY = e.clientY - drag.offsetTop
        //当拉着box移动时
        document.onmousemove = function(e) {
            // 浏览器兼容
            e = e || window.event
            let left = e.clientX - diffX
            let top = e.clientY - diffY
            if (left < 0) {
                left = 0
            } else if (left > window.innerWidth - drag.offsetWidth) {
                left = window.innerWidth - drag.offsetWidth
            }
            if (top < 0) {
                top = 0
            } else if (top > window.innerHeight - drag.offsetHeight) {
                top = window.innerHeight - drag.offsetHeight
            }
            drag.style.left = left + 'px'
            drag.style.top = top + 'px'
        }
        // 当鼠标抬起时
        document.onmouseup = function(e) {
            this.onmousemove = null
            this.onmouseup = null
        }
    }
}

4.关闭弹窗的方法?

本文含有隐藏内容,请 开通VIP 后查看