webdevda
webdevda
Task-
Webpage using Javascript with chatbot
Webpage:
My site is live at:
https://atharvabhangale.github.io/VRwebpage/
Code:
Html:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Landing Product</title>
<div class="container">
<h3 class="short">How it Works</h3>
<h2 class="title">Principal functions</h2>
<p class="desc">Discover the core functionalities that make
our product stand out:</p>
<div class="grid grid3">
<div class="functions col-left">
<ul>
<li>
<i class="fab fa-algolia"></i>
<h3>Fast</h3>
<p>Experience lightning-fast performance that
keeps you productive and efficient</p>
</li>
<li>
<i class="fas fa-shield-alt"></i>
<h3>Security</h3>
<p>Rest assured knowing that your data and
information are protected with advanced security features.</p>
</li>
</ul>
</div>
<div class="functions-image wow animate__animated
animate__backInUp">
<img src="img/img1.jpeg" alt="product image">
</div>
<div class="functions">
<ul>
<li>
<i class="fas fa-microchip"></i>
<h3>Monitor</h3>
<p>Keep track of important data and metrics
with our intuitive monitoring system.</p>
</li>
<li>
<i class="fas fa-memory"></i>
<h3>Alarm</h3>
<p>Stay alert and informed with our reliable
alarm system, ensuring you never miss a critical event.</p>
</li>
</ul>
</div>
</div>
</div>
</section>
</main>
<!-- FOOTER -->
<footer class="section">
<div class="container">
<ul class="social list-inline">
<li>
<a href="#">
<i class="fab fa-facebook-square"></i>
</a>
</li>
<li>
<a href="#">
<i class="fab fa-instagram-square"></i>
</a>
</li>
<li>
<a href="#">
<i class="fab fa-twitter-square"></i>
</a>
</li>
<li>
<a href="#">
<i class="fab fa-linkedin"></i>
</a>
</li>
</ul>
<p>
Copyright 2024 - <strong>Immersitech</strong>
</p>
</div>
</footer><div class="parent">
<div class="desc">
<h1 class="text">AssistPro</h1>
<p>Your Personal Guide to Seamless Support and Instant
Assistance</p>
<button id="init">START CHAT</button>
</div>
<div>
<img src="img/chatbot.png" alt="" class="bot-img">
</div>
</div>
<div id="test" style="position: fixed;top: 4rem;right: 8rem;display:
none;">
<div class="child" id="chatbot">
<div class="header">
<div class="h-child">
<img src="img/chatbot (1).png" alt="avatar" id="avatar">
<div>
<span class="name">AssistPRO</span>
<br>
<span style="color:lawngreen">online</span>
</div>
</div>
<div>
<button class="refBtn"><i class="fa fa-refresh"
onclick="initChat()"></i></button>
</div>
</div>
<div id="chat-box">
</div>
<div class="footer">
<span>powered by @atharva</span>
</div>
</div>
</div>
Css:
/* pallete color */
:root{
--color-dark:#4b45dd;
--color-main:#6862f4;
--color-gray:#7b8da0;
--color-gray1:#424242;
--color-light:#f4f4ff;
}
*{
padding: 0;
margin:0;
box-sizing: border-box;
font-family: 'Montserrat', sans-serif;
font-weight: 400;
}
html {
scroll-behavior: smooth;
}
a{
text-decoration: none;
color: var(--color-main);
}
p{
font-size: .9em;
}
strong{
font-weight: 600;
}
.grid{
display: grid;
gap:20px 10px;
}
.grid2{
grid-template-columns: repeat(2, 1fr);
}
.grid3{
grid-template-columns: repeat(3, 1fr);
}
.grid4{
grid-template-columns: repeat(4, 1fr);
}
.grid img{
max-width: 100%;
}
.container{
width: 100%;
max-width: 1320px;
margin: 0 auto;
padding:0 25px;
}
.list-inline li{
display: inline-block;
list-style-type: none;
}
.bg-image{
background-repeat: no-repeat;
background-size: cover;
background-position:center;
}
h1{
font-weight: 700;
}
h2, h3{
font-weight: 600;
}
.btn-link {
border: 2px solid var(--color-main);
color: var(--color-main);
font-size: .8em;
display: inline-block;
font-weight: 600;
border-radius: 5px;
padding: 8px 15px;
}
.btn-link:hover{
background-color: var(--color-main);
color:#fff;
}
.btn-link-light{
border: 2px solid #fff;
}
/* all sections */
.section{
padding: 80px 0;
}
.section .short,
.section .title,
.section .desc{
text-align: center;
margin-bottom: 10px;
}
.section .short{
color: var(--color-main);
text-transform: uppercase;
font-size: .9em;
}
.section .desc{
margin-bottom: 40px;
font-size: .9em;
}
/* header nav */
header {
position: fixed;
width: 100%;
z-index: 1;
}
.grid-header{
grid-template-columns: 200px 1fr;
align-items: center;
}
.logo img {
max-width: 180px;
padding: 4px 0;
}
/* menu */
.btn-menu-toggle{
display: none;
padding: 10px;
justify-self:end;
}
.menu {
text-align: right;
}
.menu li {
padding: 5px 10px;
}
.menu li a {
color:var(--color-light);
font-weight: 600;
text-transform: uppercase;
font-size: .85em;
}
.menu li a:hover {
text-decoration: underline;
}
/* header sticky */
.sticky{
background-color: var(--color-dark);
box-shadow: 1px 1px 10px gray;
}
/* intro */
#intro{
background-image: url(../img/bg-top.png);
padding-top: 120px;
}
#intro .container{
max-width: 1000px;
padding:5px 25px;
}
.intro-img img {
width: 100%;
max-width: 390px;
margin: 0 auto;
display: block;
}
.intro-desc * {
color: #fff;
}
.intro-desc h1,
.intro-desc h3,
.intro-desc p {
margin-bottom:20px
}
.intro-desc h1{
font-size: 2em;
}
/* how to work */
#howto .grid{
grid-template-areas: "detail1 img detail2";
}
.functions ul{
padding: 10px 30px;
}
#howto .grid div:nth-child(1){
grid-area: detail1;
}
#howto .grid div:nth-child(2){
grid-area: img;
}
#howto .grid div:nth-child(3){
grid-area: detail2;
}
.functions li {
padding: 10px;
list-style-type: none;
margin: 5px 0 20px;
font-size: .9em;
}
.functions li i {
font-size: 2em;
margin-bottom: 10px;
color: var(--color-main);
}
.functions li h3{
margin-bottom: 10px;
}
.functions-image img {
width: 100%;
max-width: 300px;
margin: 0 auto;
display: block;
}
.col-left li {
text-align: right;
}
/* features */
#features{
background-color: var(--color-light);
}
#features .container{
max-width:1000px;
}
.feature {
padding: 50px 20px;
box-shadow: 1px 1px 15px var(--color-light);
text-align:center;
background-color: #fff;
}
.feature i {
color: var(--color-main);
font-size: 2.8em;
margin: 20px 0;
}
.feature h3 {
margin-bottom: 10px;
font-weight: 500;
}
.feature:hover{
background: linear-gradient(0deg, #6862f4 21%, #6862f4a4 79%);
}
.feature:hover *{
color:#fff;
}
/* video demo */
.bg-video{
background-image: url(../img/bg-video.png);
background-attachment: fixed;
}
section#demo{
text-align:center;
}
section#demo .title,
section#demo .desc,
section#demo .btn-play {
color: #fff;
}
section#demo .btn-play i{
font-size:5em
}
#demo .btn-play:hover i{
transform:scale(1.1);
}
/* reviews */
#reviews{
background-color: var(--color-light);
}
.review {
text-align: center;
padding: 15px 0;
}
.review img {
max-width: 150px;
}
.review blockquote {
font-style: italic;
margin: 15px 10px;
}
.review h3 {
font-size: .9em;
}
/* pricing */
.info {
padding: 40px 10px;
align-self: center;
}
.info h2 {
margin-bottom: 20px;
}
.info p {
margin-bottom: 10px;
}
.model {
text-align: center;
border: 1px solid var(--color-light);
padding: 40px 25px;
border-radius: 5px;
}
.model i {
color: var(--color-gray1);
font-size: 2em;
margin-bottom: 20px;
}
.model h3 {
color: var(--color-main);
margin-bottom: 20px;
font-weight: 600;
font-size: 1.4em;
}
.model h4 {
margin-bottom: 5px;
}
.model ul{
margin-bottom:40px
}
.model ul li {
text-align: left;
list-style-type: none;
padding: 10px 0;
font-size: .85em;
position: relative;
padding-left: 20px;
}
.model ul li:before{
content: "\f058";
font-family: 'Font Awesome 5 Free';
color: var(--color-main);
position: absolute;
left: 0;
}
/* contact */
#contact{
position: relative;
background-color: var(--color-light);
}
.bg-contact{
background-image: url(../img/img4.jpeg);
position: absolute;
left: 0;
width: 50%;
height: 100%;
}
.section-contact h2{
margin-bottom:10px
}
.section-contact p{
margin-bottom:20px
}
.section-contact {
padding: 80px 60px;
}
.section-contact form input,
.section-contact form button{
width: 100%;
margin-bottom: 15px;
padding: 12px 10px;
border-radius:4px;
border:1px solid var(--color-gray);
}
.section-contact form button {
background-color:var(--color-main);
border:0;
color:#fff;
}
/* footer */
footer ul,
footer p{
text-align: center;
}
ul.social i {
font-size: 1.5em;
}
ul.social a {
margin: 0 10px;
}
ul.social {
margin-bottom: 20px;
}
@media (max-width: 480px) {
/* reset grid */
.grid{
gap:initial;
}
.grid2,
.grid3,
.grid4{
grid-template-columns: 1fr;
}
/* header */
.btn-menu-toggle{
display: block;
background-color: transparent;
border: 1px solid var(--color-light);
color: var(--color-light);
}
.btn-menu-toggle i {
font-size: 1.2em;
}
/* menu */
.menu {
width: 100%;
position: absolute;
left: 0;
top: 64px;
background-color: var(--color-dark);
box-shadow: 1px 3px 5px #928dff;
height: 0;
overflow: hidden;
}
.menu li {
width: 100%;
text-align: left;
padding: 10px 20px!important;
}
.menu.show{
height: 270px;
}
/* how to */
#howto .grid{
grid-template-areas: 'detail1 detail2'
'img img';
grid-template-columns:auto;
}
.functions ul {
padding: 10px;
}
.functions ul li {
text-align: center;
}
Javascript:
// When the user scrolls the page, execute myFunction
window.onscroll = () => stickyMenu();
}
}
btnMenuToggle.addEventListener("click", actionMenu);
var data= {
chatinit:{
title: ["Welcome to ImmersiTech VR! I'm here to assist you. How can I
help you today?"],
options: ["Explore VR Experiences","Discover Upcoming Events","Get
Headset Recommendations","Learn About EducationalContent"]
},
explorevrexperiences: {
title:["Please select category"],
options:['Gaming Experiences','Educational Simulations','Virtual
Tours','Immersive Storytelling'],
url : {
}
},
discoverupcomingevents: {
title:["Virtual Reality Conference: Future Frontiers"],
options:["Join us for an immersive journey into the future of virtual
reality at the Virtual Reality Conference: Future Frontiers, hosted by
ImmersiTech. This groundbreaking event brings together VR enthusiasts,
industry experts, and thought leaders for an exploration of the latest trends,
innovations, and possibilities in the world of VR technology."],
url : {
more:"https://www.youtube.com",
link:["https://www.youtube.com","https://www.youtube.com","https:/
/www.youtube.com","https://www.youtube.com"]
}
},
getheadsetrecommendations: {
title:["Unveiling Your Path to Virtual Reality: Explore Our Range of
Packages and Find the Perfect Fit for Your Needs and Budget"],
options:['Basic','Advance','Premium'],
url : {
}
},
learnabouteducationalcontent: {
title:["Thanks for your response","Here are some electronic items for
you","Click on it to know more"],
options:['History Exploration','Science Adventures','Geography
Expeditions','Art and Culture Immersion'],
url : {
more:"https://www.youtube.com",
link:["#","#","#","#","#"]
}
},
basic: {
title:["Thanks for your response","Here is more information about
basic verison","Click on it to know more"],
options:['Display','Camera','Processor','Comfort'],
url : {
more:"https://www.youtube.com",
link:["#","#","#","#"]
}
},
advance: {
title:["Thanks for your response","Here is more information about
Advance verison","Click on it to know more"],
options:['Display','Camera','Processor','Comfort'],
url : {
more:"https://www.youtube.com",
link:["#","#","#","#"]
}
},
premium: {
title:["Thanks for your response","Here is more information about
Premium verison","Click on it to know more"],
options:['Display','Camera','Processor','Comfort'],
url : {
more:"https://www.youtube.com",
link:["#","#","#","#"]
}
},
historyexploration: {
title:["Thanks for your response","These are some results based on
your input","Click on it to know more"],
options:['Clothing','Western Wear','Ethnic Wear','Top Brands'],
url : {
more:"https://www.youtube.com",
link:["#","#","#","#"]
}
},
scienceadventures: {
title:["These are some of latest discoveries and adventures in
Science"],
options: ["Meta Quest","Sora AI","Apple Vision Pro","Immersitech
VR","Chatgpt 4"],
url : {
more:"https://www.youtube.com",
link:["https://www.youtube.com","https://www.youtube.com","https:/
/www.youtube.com","https://www.youtube.com"]
}
},
gamingexperiences: {
title: ["Thanks for your response","Here are Virtual Gaming
Experiences"],
options: ["Palworld","Witcher 3","Star Citizen","Call of Duty","Gta
5"],
url: {
more:"https://www.youtube.com",
link:["#","#","#","#","#"]
}
},
educationalsimulations: {
title: ["Thanks for your response","Here are V"],
options: ["Mechanical","Comp
Bio","Agriculture","Biotechnology","Sustainable Development"],
url: {
more:"https://www.youtube.com",
link:["#","#","#","#","#"]
}
},
virtualtours: {
title: ["Thanks for your response","Here are some of our handpicked
Virtual tours"],
options: ["Bali","Tokyo","Switzerland","Maldives","Kashmir"],
url: {
more:"https://www.youtube.com",
link:["#","#","#","#","#"]
}
},
immersivestorytelling: {
title: ["Here are some more options for you"],
options: ["YouTube","Netflix","Amazon Prime","Hot Star"],
url: {
more:"https://www.youtube.com/",
link:["#","#","#","#","#"]
}
},
}
document.getElementById("init").addEventListener("click",showChatBot);
var cbot= document.getElementById("chat-box");
function showChatBot(){
console.log(this.innerText);
if(this.innerText=='START CHAT'){
document.getElementById('test').style.display='block';
document.getElementById('init').innerText='CLOSE CHAT';
initChat();
}
else{
location.reload();
}
}
function remove_spaces(str) {
let new_str = ""
for(let i = 0; i < str.length; i++) {
if (str[i] != " ") {
new_str += str[i].toLowerCase()
}
}
return new_str
}
function initChat(){
j=0;
cbot.innerHTML='';
for(var i=0;i<len1;i++){
setTimeout(handleChat,(i*500));
}
setTimeout(function(){
showOptions(data.chatinit.options)
},((len1+1)*500))
}
var j=0;
function handleChat(){
console.log(j);
var elm= document.createElement("p");
elm.innerHTML= data.chatinit.title[j];
elm.setAttribute("class","msg");
cbot.appendChild(elm);
j++;
handleScroll();
}
function showOptions(options){
for(var i=0;i<options.length;i++){
var opt= document.createElement("span");
var inp= '<div>'+options[i]+'</div>';
opt.innerHTML=inp;
opt.setAttribute("class","opt");
opt.addEventListener("click", handleOpt);
cbot.appendChild(opt);
handleScroll();
}
}
function handleOpt(){
console.log(this);
var findText= this.innerText;
document.querySelectorAll(".opt").forEach(el=>{
el.remove();
})
var elm= document.createElement("p");
elm.setAttribute("class","test");
var sp= '<span class="rep">'+this.innerText+'</span>';
elm.innerHTML= sp;
cbot.appendChild(elm);
function handleDelay(title){
var elm= document.createElement("p");
elm.innerHTML= title;
elm.setAttribute("class","msg");
cbot.appendChild(elm);
}
function handleResults(title,options,url){
for(let i=0;i<title.length;i++){
setTimeout(function(){
handleDelay(title[i]);
},i*500)
if(isObjectEmpty(url)==true){
console.log("having more options");
setTimeout(function(){
showOptions(options);
},title.length*500)
}
else{
console.log("end result");
setTimeout(function(){
handleOptions(options,url);
},title.length*500)
}
}
function handleOptions(options,url){
for(var i=0;i<options.length;i++){
var opt= document.createElement("span");
var inp= '<a class="m-link"
href="'+url.link[i]+'">'+options[i]+'</a>';
opt.innerHTML=inp;
opt.setAttribute("class","opt");
cbot.appendChild(opt);
}
var opt= document.createElement("span");
var inp= '<a class="m-link" href="'+url.more+'">'+'See more</a>';
console.log(isObjectEmpty(url));
console.log(url);
opt.innerHTML=inp;
opt.setAttribute("class","opt link");
cbot.appendChild(opt);
handleScroll();
}
function handleScroll(){
var elem= document.getElementById('chat-box');
elem.scrollTop= elem.scrollHeight;
}