Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* -----------------------------------------------
- /* How to use? : Check the GitHub README
- /* ----------------------------------------------- */
- /* To load a config file (particles.json) you need to host this demo (MAMP/WAMP/local)... */
- /*
- particlesJS.load('particles-js', 'particles.json', function() {
- console.log('particles.js loaded - callback');
- });
- */
- /* Otherwise just put the config content (json): */
- // @ts-nocheck
- const johnSelectorBtn = document.querySelector('#john-selector')
- const janeSelectorBtn = document.querySelector('#jane-selector')
- const chatHeader = document.querySelector('.chat-header')
- const chatMessages = document.querySelector('.chat-messages')
- const chatInputForm = document.querySelector('.chat-input-form')
- const chatInput = document.querySelector('.chat-input')
- const clearChatBtn = document.querySelector('.clear-chat-button')
- const messages = JSON.parse(localStorage.getItem('messages')) || []
- const createChatMessageElement = (message) => `
- <div class="message ${message.sender === 'John' ? 'blue-bg' : 'gray-bg'}">
- <div class="message-sender">${message.sender}</div>
- <div class="message-text">${message.text}</div>
- <div class="message-timestamp">${message.timestamp}</div>
- </div>
- `
- window.onload = () => {
- messages.forEach((message) => {
- chatMessages.innerHTML += createChatMessageElement(message)
- })
- }
- let messageSender = 'John'
- const updateMessageSender = (name) => {
- messageSender = name
- chatHeader.innerText = `${messageSender} chatting...`
- chatInput.placeholder = `Type here, ${messageSender}...`
- if (name === 'John') {
- johnSelectorBtn.classList.add('active-person')
- janeSelectorBtn.classList.remove('active-person')
- }
- if (name === 'Jane') {
- janeSelectorBtn.classList.add('active-person')
- johnSelectorBtn.classList.remove('active-person')
- }
- /* auto-focus the input field */
- chatInput.focus()
- }
- johnSelectorBtn.onclick = () => updateMessageSender('John')
- janeSelectorBtn.onclick = () => updateMessageSender('Jane')
- const sendMessage = (e) => {
- e.preventDefault()
- const timestamp = new Date().toLocaleString('en-US', { hour: 'numeric', minute: 'numeric', hour12: true })
- const message = {
- sender: messageSender,
- text: chatInput.value,
- timestamp,
- }
- /* Save message to local storage */
- messages.push(message)
- localStorage.setItem('messages', JSON.stringify(messages))
- /* Add message to DOM */
- chatMessages.innerHTML += createChatMessageElement(message)
- /* Clear input field */
- chatInputForm.reset()
- /* Scroll to bottom of chat messages */
- chatMessages.scrollTop = chatMessages.scrollHeight
- }
- chatInputForm.addEventListener('submit', sendMessage)
- clearChatBtn.addEventListener('click', () => {
- localStorage.clear()
- chatMessages.innerHTML = ''
- })
- particlesJS('particles-js',
- {
- "particles": {
- "number": {
- "value": 80,
- "density": {
- "enable": true,
- "value_area": 800
- }
- },
- "color": {
- "value": "#ffffff"
- },
- "shape": {
- "type": "circle",
- "stroke": {
- "width": 0,
- "color": "#000000"
- },
- "polygon": {
- "nb_sides": 5
- },
- "image": {
- "src": "img/github.svg",
- "width": 100,
- "height": 100
- }
- },
- "opacity": {
- "value": 0.5,
- "random": false,
- "anim": {
- "enable": false,
- "speed": 1,
- "opacity_min": 0.1,
- "sync": false
- }
- },
- "size": {
- "value": 5,
- "random": true,
- "anim": {
- "enable": false,
- "speed": 40,
- "size_min": 0.1,
- "sync": false
- }
- },
- "line_linked": {
- "enable": true,
- "distance": 150,
- "color": "#ffffff",
- "opacity": 0.4,
- "width": 1
- },
- "move": {
- "enable": true,
- "speed": 6,
- "direction": "none",
- "random": false,
- "straight": false,
- "out_mode": "out",
- "attract": {
- "enable": false,
- "rotateX": 600,
- "rotateY": 1200
- }
- }
- },
- "interactivity": {
- "detect_on": "canvas",
- "events": {
- "onhover": {
- "enable": true,
- "mode": "repulse"
- },
- "onclick": {
- "enable": true,
- "mode": "push"
- },
- "resize": true
- },
- "modes": {
- "grab": {
- "distance": 400,
- "line_linked": {
- "opacity": 1
- }
- },
- "bubble": {
- "distance": 400,
- "size": 40,
- "duration": 2,
- "opacity": 8,
- "speed": 3
- },
- "repulse": {
- "distance": 200
- },
- "push": {
- "particles_nb": 4
- },
- "remove": {
- "particles_nb": 2
- }
- }
- },
- "retina_detect": true,
- "config_demo": {
- "hide_card": false,
- "background_color": "#b61924",
- "background_image": "",
- "background_position": "50% 50%",
- "background_repeat": "no-repeat",
- "background_size": "cover"
- }
- }
- );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement