Skip to content

Latest commit

 

History

History
53 lines (33 loc) · 1.15 KB

README.md

File metadata and controls

53 lines (33 loc) · 1.15 KB

selectors-observer

可以快速获取用户正在阅读内容的锚点的工具库,框架通用

先看效果

react demo

install

CDN

<script src="https://yrobot.github.io/selectors-observer/lib/index.umd.js"></script>

在使用SelectorsObserver前利用 script 标签引入,然后就可以直接在 js 逻辑中直接使用SelectorsObserver

npm

yarn add selectors-observer

or

npm install selectors-observer

usage

import SelectorsObserver from 'selectors-observer';

const selectors = ['#anchor1', '#anchor2', '#anchor3'];

const oberver = new SelectorsObserver();

oberver.select(selectors).listen((selecor) => {
  // 每次正在浏览的锚点变更时,会触发listen
  setViewing(selecor);
});

demo on codesandbox

static html demo

react demo