Git Product home page Git Product logo

emotion's Introduction

聊天应用中的表情插件

用于即时聊天应用的图片表情插件,具有展示表情、插入表情和表情编解码的功能

项目地址

看代码

看demo

原理介绍

web端的即时聊天中看到的表情,其实就是一张张表情图片,通过img标签引用并展示在页面上。在整个聊天的流程上主要有这几个要点:

  • 当用户要发送表情时,首先要显示表情列表,让用户可以从中选择要发送的表情。然后通过插入表情的功能,将表情插入到当前光标所在的位置。这里有一个小技巧,如果输入框用<input type="text">的话,是无法在输入框中显示表情图片的,这样用户无法直观的看到他想发送的表情。可以使用H5中的新特性contenteditable,使div变为可编辑状态,就可以显示表情图片了。
  • 用户点击了发送之后,将输入框中的内容进行编码,用户输入框中的内容应该类似于你好啊<img src="arclist/1.gif">,编码之后会得到你好啊[em_1],就可以将之发送或者存储。
  • 当用户页面读取到聊天内容时,会得到你好啊[em_1]这样的字符串,其中[em_1]就是表情图片对应的编码,进行解码后,[em_1]会解析成<img src="arclist/1.gif">,然后直接渲染到页面中,用户就能看到对应的表情图片了。

代码注释比较详细,使用的时候可以根据项目的具体情况,做一些适当的修改。

emotion's People

Contributors

j20041426 avatar

Watchers

 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.