I'm making a simple chatbot system and I want the chatbot to automatically scroll to bottom of the chat after user input. this is my index.php:
<!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, height=device-height, initial-scale=1.0">
<title>Chatbot</title>
<?PHP
echo shell_exec("python test.py 'parameter1'");
?>
<link rel="stylesheet" href="static/css/chat.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
</head>
<body>
<!-- CHAT BAR BLOCK -->
<div class="container">
<div class="top-bar">
<p style="color:white; text-align: center">Security Chatbot
<i id="chat-icon" style="color: white;" class="fa fa-fw fa-comments-o"></i>
</p>
</div>
<div class="chatbot">
<!-- Message Container -->
<div class="outer-container">
<div class="chat-container">
<!-- Messages -->
<div id="chatbox">
<h5 id="chat-timestamp" style="text-align: center;"></h5>
<p id="botStarterMessage" class="botText" name="botresponse"></p>
<button id="option1" >Phishing Attack</button>
<button id="option2" >Denial of Service (DoS) Attack</button>
<button id="option3" >Password Attack</button>
<button id="option4" >Malware Attack</button>
<button id="option5" >Cloud Attack</button>
</div>
</div>
</div>
</div>
<!-- User input box -->
<div class="chatbar_input_block">
<div id="userInput">
<input id="textInput" class="input-box" type="text" name="textInput"
placeholder="Tap 'Enter' to send a message" autofocus="on">
<p></p>
</div>
<div class="chat-bar-icons">
<i id="chat-icon" style="color: #333;" class="fa fa-fw fa-send" onclick="sendButton()"></i>
</div>
</div>
<div id="chat-bar-bottom">
<p></p>
</div>
</div>
</body>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<!-- <script src="static/scripts/responses.js"></script> -->
<script src="static/scripts/chat.js"></script>
<!-- <script type=text/javascript>
function scroll(){
var scrollMsg = document.querySelector('outer-container');
scrollMsg.scrollTop = scrollMsg.scrollHeight;
}
scroll();
</script> -->
as u can see I've tried the scroll() function. but it doesn't work I've also tried scrollintoview function which is in the chat.js file.
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
it used to work but after I added some css and html code it just doesn't work anymore may I know any fix for this? this is css
html {
scroll-behavior: smooth;
font-family: 'Times New Roman', Times, serif;
}
body {
background-color: lightblue;
margin: 0 auto;
align-items: center;
overflow: hidden;
}
.container {
margin: 2% auto;
cursor: pointer;
width: 60%;
min-width: 600px;
height: 560px;
font-size: 18px;
box-shadow: 0 8px 16px 0 rgba(0, 0, 0, 0.2);
border-radius: 10px;
/* overflow: auto; */
}
.top-bar {
background-color: darkblue;
border-radius: 10px 10px 0px 0px;
height: 40px;
width: 100%;
padding: 5px;
}
.chatbot {
background-color: #f1f1f1;
height: 445px;
padding: 3px;
overflow: auto;
}
.outer-container {
min-height: 100%;
bottom: 0%;
position: relative;
overflow: auto;
}
.chat-container {
position: absolute;
bottom: 0;
max-height: 100%;
text-align: center;
width: 100%;
overflow-y: scroll;
overflow: auto;
hyphens: auto;
scroll-behavior: smooth;
flex-direction: column-reverse;
}
::-webkit-scrollbar {
width: 8px;
}
::-webkit-scrollbar-track {
background: #f1f1f1;
}
::-webkit-scrollbar-thumb {
background: #888;
}
::-webkit-scrollbar-thumb:hover {
background: #555;
}
/* Chat Input Bar */
.chatbar_input_block {
width: 100%;
height: 75px;
bottom: 0;
float: left;
box-sizing: border-box;
justify-content: space-between;
align-items: center;
background-color: lightcoral;
padding: 0px 0px 2px 12px;
border-radius: 0px 0px 10px 10px;
}
.chat-bar-icons {
padding: 7px 0px 0px 1px;
justify-content: space-evenly;
box-sizing: border-box;
width: 10%;
float: right;
font-size: 25px;
}
/* Chat bubbles */
#userInput {
width: 87%;
}
.input-box {
float: left;
border: none;
box-sizing: border-box;
width: 100%;
border-radius: 10px;
padding: 12px;
font-size: 16px;
color: #000;
background-color: white;
outline: none
}
.userText {
color: white;
font-family: Helvetica;
font-size: 16px;
font-weight: normal;
text-align: right;
clear: both;
}
.userText span {
line-height: 1.5em;
display: inline-block;
background: #5ca6fa;
padding: 10px;
border-radius: 8px;
border-bottom-right-radius: 2px;
max-width: 80%;
margin-right: 10px;
animation: floatup .5s forwards
}
.botText {
color: #000;
font-family: Helvetica;
font-weight: normal;
font-size: 16px;
text-align: left;
}
.botText span {
line-height: 1.5em;
display: inline-block;
background: #e0e0e0;
padding: 10px;
border-radius: 8px;
border-bottom-left-radius: 2px;
max-width: 80%;
margin-left: 10px;
animation: floatup .5s forwards
}
/* @keyframes floatup {
from {
transform: translateY(14px);
opacity: .0;
}
to {
transform: translateY(0px);
opacity: 1;
}
}
/* Desktops and laptops ----------- */
@media screen and (min-width : 1024px) and (max-height: 1310px) {
.container {
width: 60%;
height: 60%;
}
}
/* Large screens ----------- */
@media only screen and (min-width : 1324px) and (max-height: 1600px) {
.container {
width: 60%;
height: 80%;
}
}