text-cursor-prompt
介绍
在某些场景,我们希望在输入框输入文字时,在当前光标下方会有一个提示框,提示框中的内容可以是我们自己就写好的,也可以是调用接口返回的动态数据。另外,提示框完全可自定义。
演示
快速使用
安装
npm install --save text-cursor-prompt
使用
- textEle: 输入标签元素,比如 textarea、input
- promptContainer: 提示框容器,决定了提示框的位置等
- promptTextELe: 可以是一个
p
标签,决定了显示的内容,可以是纯文本,也可以含有标签节点 - config:
text
为提示内容xOffset || yOffset
可调整偏移位置,moveDuration
是框移动速度
**注: html 引用需要下载 dist/index_bundle.js
手动引入,在 React 中要手动 import 'text-cursor-prompt';
**
const textEle = document;const promptContainer = document;const promptContent = document; const config = text: 'I am the text you want to show' xOffset: -5 yOffset: 26 moveDuration: 02 const popTextCursorPrompt = textEle promptContainer promptTextELe config; popTextCursorPromptstart; // you also can change the text what you want to show at any timeconst newText = 'new text that you wan to show';popTextCursorPrompt; // you want to close this feature when something finished// you can do that as the followed code// popTextCursorPrompt.end();
项目运行
在终端一步一步执行:
git clone git@github.com:vortesnail/text-cursor-prompt.git
进入 clone 下来的文件
npm install -g http-servernpm run example
浏览器窗口打开 http://localhost:8880/example/index.html
即可查看样例
注意
我们的标签结构和 css 样式最好如下,其中 position
的设置最为重要,不然可能会出现不可预知的错误
index.html
Tip
index.css
LICENSE
MIT