Coder Social home page Coder Social logo

Comments (9)

Wujinbo666 avatar Wujinbo666 commented on July 26, 2024 1

太牛了

from front-end-articles.

NameWjp avatar NameWjp commented on July 26, 2024

有个疑问:https://developer.mozilla.org/zh-CN/docs/Web/API/PerformanceObserver/observe 这个方法接受的参数是 entryTypes 而且没有 buffered 参数,而且 entryTypes 中没有 layout-shift 的 value (https://developer.mozilla.org/zh-CN/docs/Web/API/PerformanceEntry/entryType),所以这些参数的文档是哪里查的,还是说已经是过时的,文档没有记载?

from front-end-articles.

woai3c avatar woai3c commented on July 26, 2024

https://developer.mozilla.org/zh-CN/docs/Web/API/PerformanceObserver/observe

https://developer.mozilla.org/en-US/docs/Web/API/PerformanceObserver/observe 看下英文的,中文翻译有问题。

from front-end-articles.

NameWjp avatar NameWjp commented on July 26, 2024

https://developer.mozilla.org/zh-CN/docs/Web/API/PerformanceObserver/observe

https://developer.mozilla.org/en-US/docs/Web/API/PerformanceObserver/observe 看下英文的,中文翻译有问题。

感谢

from front-end-articles.

tabooc avatar tabooc commented on July 26, 2024

isInScreen方法不能准确判断元素是否在可视窗口内,

const viewportWidth = window.innerWidth
const viewportHeight = window.innerHeight

// dom 对象是否在屏幕内
function isInScreen(dom) {
    const rectInfo = dom.getBoundingClientRect()
    if (rectInfo.left < viewportWidth && rectInfo.top < viewportHeight) {
        return true
    }

    return false
}

按上面代码的判断方式,滚动到第二屏的时候,第一屏的元素还符合isInScreen。

from front-end-articles.

woai3c avatar woai3c commented on July 26, 2024

isInScreen方法不能准确判断元素是否在可视窗口内,

const viewportWidth = window.innerWidth
const viewportHeight = window.innerHeight

// dom 对象是否在屏幕内
function isInScreen(dom) {
    const rectInfo = dom.getBoundingClientRect()
    if (rectInfo.left < viewportWidth && rectInfo.top < viewportHeight) {
        return true
    }

    return false
}

按上面代码的判断方式,滚动到第二屏的时候,第一屏的元素还符合isInScreen。

const viewportWidth = window.innerWidth
const viewportHeight = window.innerHeight

// dom 对象是否在屏幕内
function isInScreen(dom) {
    const rectInfo = dom.getBoundingClientRect()
    if (
        rectInfo.left >= 0 
        && rectInfo.left < viewportWidth
        && rectInfo.top >= 0
        && rectInfo.top < viewportHeight
    ) {
        return true
    }
}

用这个,文章里的不是最新版。

from front-end-articles.

dztony avatar dztony commented on July 26, 2024

学习

from front-end-articles.

mazhiwuzhe avatar mazhiwuzhe commented on July 26, 2024

getBoundingClientRect获取元素几何属性的时候,会导致回流吧?
是不是有性能问题

from front-end-articles.

woai3c avatar woai3c commented on July 26, 2024

getBoundingClientRect获取元素几何属性的时候,会导致回流吧? 是不是有性能问题

这个方法是获取 DOM 属性用的,并不是设置这个 DOM 元素的属性值,所以不会导致回流。

from front-end-articles.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.