Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

taro-dom-align

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

taro-dom-align

taro dom-align

  • 1.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
21
decreased by-16%
Maintainers
1
Weekly downloads
 
Created
Source

taro-dom-align NPM Version License

Taro 中使用 dom-align,部分代码的实现参考了 dom-align

安装

Taro 2

# yarn
yarn add taro-dom-align

# npm
npm i taro-dom-align --save

使用

import useDomAlign from 'taro-dom-align'

// 与原版 dom-align 不同, 
// sourceStyle 绑定在 source 元素上
// doAlign 计算 source 的定位
// setSourceStyle 自定义 source 的样式
const alignConfig = {
  points: ['tl', 'br']
}
const [sourceStyle, doAlign, setSourceStyle] = useDomAlign('.source', '.target', alignConfig)

alignConfig 参数详解

nametypedescription
pointsString[2]移动 source 节点的点以与 target 节点的点对齐, 例如 ['tl','br'], 将 source 节点的左上角 对齐 target 节点的右下角. point 的值可以为 't'(top), 'b'(bottom), 'c'(center), 'l'(left), 'r'(right)

Demo

import { View, Button } from '@tarojs/components';
import useDomAlign from 'taro-dom-align';

function Page (){
  const [sourceStyle, doAlign, setSourceStyle] = useDomAlign('.source', '.target', {
    points: ['tl', 'br'],
  });

  const handleClick = () => {
    if (sourceStyle.display === 'none') {
      doAlign();
    } else {
      setSourceStyle({
        display: 'none',
      });
    }
  };
  return (
    <View>
      <View className='target'>
        <Button onClick={handleClick}>
          target
        </Button>
      </View>
      <View className='source' style={sourceStyle}>
        source
      </View>
    </View>
  );
};

TODO

  • 设置 source 的偏移值,与原版的 alignConfig offset 效果一致
  • 设置 target 的偏移值,与原版的 alignConfig -- targetOffset
  • 支持 taro3
  • 支持 taro1
  • 多端?

许可

MIT © John60676

Keywords

FAQs

Package last updated on 14 Aug 2020

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