Git Product home page Git Product logo

text-cursor-prompt's Introduction

text-cursor-prompt Build Status

介绍

在某些场景,我们希望在输入框输入文字时,在当前光标下方会有一个提示框,提示框中的内容可以是我们自己就写好的,也可以是调用接口返回的动态数据。另外,提示框完全可自定义。

演示

ezgif-1-e2e281568223.gif

快速使用

安装

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.querySelector('.content');
const promptContainer = document.querySelector('.prompt-container');
const promptContent = document.querySelector('#prompt-content');

const config = {
  text: 'I am the text you want to show',
  xOffset: -5,
  yOffset: 26,
  moveDuration: 0.2
}

const popTextCursorPrompt = new window.popTextCursorPrompt(textEle, promptContainer, promptTextELe, config);
popTextCursorPrompt.start();

// you want to close this feature when something finished
// you can do that as the followed code
// popTextCursorPrompt.end();

项目运行

在终端一步一步执行:

git clone [email protected]:vortesnail/text-cursor-prompt.git

进入 clone 下来的文件

npm install -g http-server
npm run example

浏览器窗口打开 http://localhost:8880/example/index.html 即可查看样例

注意

我们的标签结构和 css 样式最好如下,其中 position 的设置最为重要,不然可能会出现不可预知的错误

index.html

<div class="text">
  <textarea name="" id="" cols="30" rows="10" class="content"></textarea>
  <div class="prompt-container">
    <div class="icon"><img class="tipicon" src="./tipicon.png" alt="tipicon">Tip</div>
    <p id="prompt-content"></p>
  </div>
</div>

index.css

.text {
  width: 100%;
  height: 100%;
  box-sizing: border-box;
  position: relative;
}

.content {
  box-sizing: border-box;
  width: 100%;
  height: 100%;
  outline: none;
  border: none;
  resize: none;
  background-color: rgb(62, 64, 66);
  padding: 10px;
  font-size: 16px;
  border-radius: 4px;
  box-shadow: 4px 4px 30px #929292;
  color: white;
}

.prompt-container {
  border: 1px solid #d8d8d8;
  width: 200px;
  height: 60px;
  position: absolute;
  top: 0;
  left: 0;
  padding: 4px;
  border-radius: 4px;
  visibility: hidden;
  color: white;
}

#prompt-content {
  margin: 0;
  font-size: 14px;
  padding: 0;
  color: white;
  padding-left: 10px;
}

.icon {
  font-size: 12px;
  margin: 0;
  vertical-align: middle;
  color: white;  
  font-weight: 900;
}

.tipicon {
  width: 20px;
  height: 20px;
  vertical-align: middle;
  margin-right: 6px;
}

LICENSE

MIT

text-cursor-prompt's People

Contributors

vortesnail avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.