JSChat interface, source code is provided for free, friends who are interested in JS can study it, this is still of great help to our JS knowledge Oh~
Code:
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>PHP中文网</title> <style> *{ margin: 0; padding: 0; box-sizing: border-box; } /*chrome下能隐藏滚动条*/ ::-webkit-scrollbar{ display: none; } @keyframes text { 0% { top:50px; opacity: 0; } 100%{ top: 0; opacity: 1; } } body{ background-color: #e1e1e1; } .container{ position: relative; height: 700px; width: 400px; margin: 50px auto; background-color: #f0f0f0; border-radius: 6px; overflow: hidden; } .main{ overflow: auto; border-bottom: 60px solid #fff; padding: 20px 10px; width: 100%; height: 100%; } /*这个伪元素解决不同浏览器padding裁剪内容不一致的问题!!*/ .main:after{ display: block; content: ""; background-color: transparent; width: 100%; height: 50px; } .lineBox{ overflow: hidden; min-height: 40px; clear: both; position: relative; } .imgWhite{ position: absolute; left: 10px; width: 40px; height: 40px; border-radius: 50%; } .imgBlue{ position: absolute; right: 10px; width: 40px; height: 40px; border-radius: 50%; } .textWhite{ /*!*解决连续字母不换行的问题*! max-width: 300px; word-wrap:break-word;*/ min-height: 40px; margin-left: 60px; margin-right: 10px; margin-bottom: 15px; padding: 10px 10px; display: inline-block; position: relative; border-radius: 6px; background-color: #ffffff; box-shadow: 0 5px 15px 0 rgba(0, 0, 0, 0.05); } .textWhite:before{ display: block; content: ""; width: 0; height: 0; position: absolute; left:-6px; top: 14px; border-top: solid 6px transparent; border-right: 6px solid #fff; border-bottom: solid 6px transparent; } .textBlue{ min-height: 40px; position: relative; float: right; margin-left: 10px; margin-right: 60px; margin-bottom: 15px; padding: 10px 10px; display: inline-block; border-radius: 6px; background-color: #2970ff; box-shadow: 0 5px 15px 0 rgba(41, 75, 255, 0.3); color: #fff; } .textBlue:before{ display: block; content: ""; width: 0; height: 0; position: absolute; right:-6px; top: 14px; border-top: solid 6px transparent; border-left: 6px solid #2970ff; border-bottom: solid 6px transparent; } .inputBox{ position: absolute; bottom: 0; left: 0; height: 60px; line-height: 60px; width: 100%; background-color: #ffffff; } .img1{ margin-left: 10px; margin-top: -3px; display: inline-block; vertical-align: middle; width: 40px; height: 40px; box-sizing: border-box; background-color: #fff; border-radius: 6px; } .textBox{ display: inline-block; line-height: 60px; right: 100px; left: 60px; position: absolute; } #text{ display: inline-block; font-size: 16px; padding: 0 0 0 10px; width: 100%; height: 40px; border-radius: 6px; border: 1px solid #e1e1e1; } #btn{ cursor: pointer; font-size: 16px; margin: 10px; display: inline-block; vertical-align: middle; float: right; height: 40px; box-sizing: border-box; width: 80px; border-radius: 6px; border: 1px solid #e1e1e1; background-color: #fff; outline: none; } #btn:hover{ color: #fff; background-color: #2970ff; } #btn:active{ box-shadow: 0 0 10px rgba(0, 0, 0, 0.2) inset; background-color: #3668ff; } </style> <script> window.onload = function () { var img1 = document.getElementsByClassName("img1"); var imgWhite = document.getElementsByClassName("imgWhite"); var imgBlue = document.getElementsByClassName("imgBlue"); var textM = document.getElementsByClassName("textM"); var textWhite = document.getElementsByClassName("textWhite"); var textBlue = document.getElementsByClassName("textBlue"); var text = document.getElementById("text"); var btn = document.getElementById("btn"); var lineBox = document.getElementsByClassName("lineBox"); var main = document.getElementsByClassName("main"); /*用来判断猫和狗的状态*/ var onOff = true; /*页面载入时聊天内容自动滚动到最下面*/ main[0].scrollTop = main[0].scrollHeight; /*切换猫狗角色*/ img1[0].onclick = function () { if (onOff === true) { this.src = "http://www.php.cn/tpl/Index/Static/img/2017_index/logo.png"; onOff = false } else { this.src = "http://www.php.cn/tpl/Index/Static/img/banner4.jpg"; onOff = true } }; btn.onclick = function () { /*先判断猫还是狗,然后往里面添加内容*/ if (onOff === true) { main[0].innerHTML += "<div class=\"lineBox\">" + "<img src="/static/imghwm/default1.png" data-src="http://www.php.cn/tpl/Index/Static/img/2017_index/logo.png" class="lazy" class=\"imgWhite\" alt="JS imitation chat page" >" + "<p class=\"textM textWhite\">" + "</p>" + "</div>"; imgWhite[imgWhite.length - 1].src = img1[0].src; textWhite[textWhite.length - 1].innerHTML = text.value; } else { main[0].innerHTML += "<div class=\"lineBox\">" + "<img src="/static/imghwm/default1.png" data-src="http://www.php.cn/tpl/Index/Static/img/2017_index/logo.png" class="lazy" class=\"imgBlue\" alt="JS imitation chat page" >" + "<p class=\"textM textBlue\">" + "</p>" + "</div>"; imgBlue[imgBlue.length - 1].src = img1[0].src; textBlue[textBlue.length - 1].innerHTML = text.value; } /*清除原有动画*/ for (var i=0;i<textM.length;i++) { textM[i].style.animation = ""; textM[i].style.animationFillMode = ""; } /*给最新的一条聊天记录绑定CSS3帧动画*/ textM[textM.length - 1].style.animation = "text 0.3s"; textM[textM.length - 1].style.animationFillMode = "forwards"; text.value = ""; /*2个滚动方法*/ /*lineBox[lineBox.length - 1].scrollIntoView();*/ main[0].scrollTop = main[0].scrollHeight; }; /*键盘回车事件*/ document.onkeyup = function (e) { if (window.event) e = window.event; var code = e.charCode || e.keyCode; if (code === 13) { btn.onclick(); } } } </script> </head> <body> <div> <div> <div> <img src="/static/imghwm/default1.png" data-src="http://www.php.cn/tpl/Index/Static/img/2017_index/logo.png" class="lazy" alt=""> <p class="textM textBlue">PHP中文网推出的那个60天的成为大牛的课程你报了嘛? </p> </div> <div> <img src="/static/imghwm/default1.png" data-src="http://www.php.cn/tpl/Index/Static/img/banner4.jpg" class="lazy" alt=""> <p class="textM textWhite">当然报啦!你也赶快报吧!马上就截止了!PHP中文网的教育实力我还是很相信的!! </p> </div> <div> <img src="/static/imghwm/default1.png" data-src="http://www.php.cn/tpl/Index/Static/img/2017_index/logo.png" class="lazy" alt=""> <p class="textM textBlue">嗯嗯~这个我知道,我也赶紧去报名了!! </p> </div> </div> <div> <img src="/static/imghwm/default1.png" data-src="http://www.php.cn/tpl/Index/Static/img/banner4.jpg" class="lazy" alt=""> <div> <input type="text" id="text"> </div> <input type="button" value="发送" id="btn"> </div> </div> </body> </html>
The above is the source code of simulated chat~Friends who are interested can use it to study~ For more articles and source codes about js, please go to PHP中文 and search
Related recommendations:
JavaScript native code to implement slideshow
The above is the detailed content of JS imitation chat page. For more information, please follow other related articles on the PHP Chinese website!

Both Python and JavaScript's choices in development environments are important. 1) Python's development environment includes PyCharm, JupyterNotebook and Anaconda, which are suitable for data science and rapid prototyping. 2) The development environment of JavaScript includes Node.js, VSCode and Webpack, which are suitable for front-end and back-end development. Choosing the right tools according to project needs can improve development efficiency and project success rate.

Yes, the engine core of JavaScript is written in C. 1) The C language provides efficient performance and underlying control, which is suitable for the development of JavaScript engine. 2) Taking the V8 engine as an example, its core is written in C, combining the efficiency and object-oriented characteristics of C. 3) The working principle of the JavaScript engine includes parsing, compiling and execution, and the C language plays a key role in these processes.

JavaScript is at the heart of modern websites because it enhances the interactivity and dynamicity of web pages. 1) It allows to change content without refreshing the page, 2) manipulate web pages through DOMAPI, 3) support complex interactive effects such as animation and drag-and-drop, 4) optimize performance and best practices to improve user experience.

C and JavaScript achieve interoperability through WebAssembly. 1) C code is compiled into WebAssembly module and introduced into JavaScript environment to enhance computing power. 2) In game development, C handles physics engines and graphics rendering, and JavaScript is responsible for game logic and user interface.

JavaScript is widely used in websites, mobile applications, desktop applications and server-side programming. 1) In website development, JavaScript operates DOM together with HTML and CSS to achieve dynamic effects and supports frameworks such as jQuery and React. 2) Through ReactNative and Ionic, JavaScript is used to develop cross-platform mobile applications. 3) The Electron framework enables JavaScript to build desktop applications. 4) Node.js allows JavaScript to run on the server side and supports high concurrent requests.

Python is more suitable for data science and automation, while JavaScript is more suitable for front-end and full-stack development. 1. Python performs well in data science and machine learning, using libraries such as NumPy and Pandas for data processing and modeling. 2. Python is concise and efficient in automation and scripting. 3. JavaScript is indispensable in front-end development and is used to build dynamic web pages and single-page applications. 4. JavaScript plays a role in back-end development through Node.js and supports full-stack development.

C and C play a vital role in the JavaScript engine, mainly used to implement interpreters and JIT compilers. 1) C is used to parse JavaScript source code and generate an abstract syntax tree. 2) C is responsible for generating and executing bytecode. 3) C implements the JIT compiler, optimizes and compiles hot-spot code at runtime, and significantly improves the execution efficiency of JavaScript.

JavaScript's application in the real world includes front-end and back-end development. 1) Display front-end applications by building a TODO list application, involving DOM operations and event processing. 2) Build RESTfulAPI through Node.js and Express to demonstrate back-end applications.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

WebStorm Mac version
Useful JavaScript development tools

Atom editor mac version download
The most popular open source editor

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.
