Skip to content

Yrobot/selectors-observer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

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

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published