New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

in-view-utils

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

in-view-utils

Detect if the dom is within the view, as well as some other dom-related helper functions.

  • 0.0.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

inViewUtils.js

  • Detect if the dom is within the view, as well as some other dom-related helper functions.
  • 中文说明
  • Online demo

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

兼容dom在父容器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

Keywords

FAQs

Package last updated on 12 Mar 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc