0.0.4 • Published 2 years ago

in-view-utils v0.0.4

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

inViewUtils.js

Install

npm i in-view-utils

Use

ES6

import {isInDomView} from "in-view-utils"
//like
isInDomView(...)

script html label

 //like
  window.inViewUtils.isInDomView({...})

The main functional functions

function namedescriptionargreturn
isInDomViewDetects whether the dom is visible inside the container domRefer to the isInDomView descriptionboolean
isInViewDetects if the dom is fully visible within the windowThe dom object being detectedboolean
getScrollableChildrenGets one scrollable child nodeRefer to the getScrollableChildren descriptiondom or null
getDomToVisbleDisGets the distance between the dom entering the dom container viewable areaRefer to the isInDomView desc{x:number,y:number}
getDomToViewVisbleDisGets the distance from the dom to the window viewableRefer to the getDomToViewVisbleDis description{x:number,y:number}

Other function

function namedescriptionargreturn
getBoundingClientRectGets the dom's rect objectdomrect object
getRectHeightGets the height of the dom rect object, if the label is rotated 90 degrees or -90 degrees, the result is based on the height of the device orientation, no longer a style attributedomnumber
getRectWidthGets the width of the dom rect object, if the label is rotated 90 degrees or -90 degrees, the result is based on the height of the device orientation, no longer a style attributedomnumber
getViewPortHeightGets the window height-number
getViewPortWidthGets the Window width-number
getBlockWidthGets the height of the view after the computed css property, which is a style property in the traditional sense-number
getBlockHeightGets the view after the width is calculated after the css property, which is a style property in the traditional sense-number
getBodyScrollYGets the body Y-axis scroll-number
getBodyScrollXGets the body X axis scroll-number
getDomScrollXGets the dom X-axis scrolldomnumber
getDomScrollYGets the dom Y axis to scrolldomnumber

Diagram

img1

img1

img2

img2

Api description

isInDomView

description

Detects whether the dom is visible in the parent container dom

arg

typeof arg == object

  • dom: The target dom of the detected
  • wrapDom: Detect the parent container (dom) of the dom
  • overallVisible: Whether the part is visible in the parent container, the default is no, if true is set, the part of the visible isInDomView function will also return true, such as img 2, otherwise it will only be true if it is shown in figure 1

getScrollableChildren

description

Get the scrollable elements in the dom, and then return, if not, null

arg

len of arg ===3

  • arg1:The dom to be detected
  • arg2:Maximum number of hierarchical traversals, default 100
  • arg3:Direction of scrolling, optional v (vertical, default) and h (horizontal scrolling)

return

A dom or null

getDomToVisbleDis

desc

Get the distance from the dom to the visual area of the container dom,

arg

typeof arg == object

  • dom :The element being detected
  • viewPort: dom (scrollable parent container)
  • yOtherHeight: The height of the bottom mask of the Y axis
  • xOtherHeight:The mask height at the bottom of the X axis
  • rotate: Container rotation angle, optional 0, 90, -90

return

{
  x:number,
  y:number
}

getDomToViewVisbleDis

desc

Gets the distance from the dom to the window area of the browser window, returns {x:number,y:number} If it is like {x:0,y:0}, it is within the visual area

arg

typeof arg == object

  • dom: The element being detected
  • yOtherHeight: The height of the bottom mask of the Y axis
  • xOtherHeight: The mask height at the bottom of the X axis

return

{
  x:number,
  y:number
}

Q&A

The difference between getRectHeight and getBlockHeight

The difference is only if the container is set to rotate 90 degrees or 90 degrees.

  1. GetRectHeight is the height obtained by gettingBoundingClientRect
  2. GetBlockHeight is the height obtained through getComputedStyle.
  1. GetBoundingClientRect is always based on the orientation of the device, and the result is the orientation of the device above the meaning of the left and right up and down and width and height
  2. GetComputedStyle simply reads the css styles that are in effect