I have a pop up tab where users can check their messages and another is their notification. Currently, when my code only has this:
<div class="inbox active" id="inbox">
<form action="includes/chatsearch-inc.php" method="POST">
<input type="text" name="search" placeholder="Search a user or applicant\'s name">
<button name="submit"><i class="fa fa-search"></i></button>
</form>
</div>
<div class="notifications" id="notifications">
<div class="notifications__container" onclick="location.href=\'job?jid='.$jobsid.'\'">
<img src="profilepic/'.$notifsusersprofilepic.'" alt="'.$notifsusersname.'\'s profile picture" class="profilepic">
<div class="notifications__info__container">
<p class="notifications__info"><b>'.$notifsusersname.'</b> applied to your job listing. </p>
<p class="notifications__info date">'.$notifsdate.'</p>
</div>
</div>
<hr class="notifications__divider">
</div>
And CSS is:
.tabs {
display: none;
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%,-50%);
width: 75%;
height: 75%;
background: #fff;
padding:2em;
overflow:hidden;
box-shadow: 0 0 40px rgba(0, 0, 0, 0.2);
border-radius: var(--border-radius);
z-index: 102;
}
.tabs .tab-header {
height:3rem;
display:flex;
align-items: center;
}
.tabs #close_header_tabs {
display: flex;
justify-content: flex-end;
}
.tabs .tab-header > div {
width:calc(100% / 2);
text-align:center;
color:#888;
font-weight:600;
cursor:pointer;
font-size:.85em;
text-transform:uppercase;
outline:none;
transition: color 0.2s;
}
.tabs .tab-header > div > i {
display:block;
margin-bottom:5px;
}
.tabs .tab-header > div.active {
color:#00acee;
}
.tabs .tab-header > div.active > i {
display:block;
color: #8bc34a;
margin-bottom:.3rem;
}
.tabs .tab-indicator {
position:relative;
width:calc(100% / 2);
height:.3rem;
background:#00acee;
left:0px;
border-radius:var(--border-radius);
transition:all 500ms ease-in-out;
}
.tabs .tab-body {
position:relative;
height:calc(100% - 60px);
padding:.6em .3em;
}
.tabs .tab-body > div {
position:absolute;
top:-200%;
opacity:0;
transform:scale(0.9);
transition:opacity 500ms ease-in-out 0ms,
transform: 500ms ease-in-out 0ms;
}
.tabs .tab-body > div.active {
top:0px;
opacity:1;
transform:scale(1);
}
.tabs .tab-header > div:hover {
color:#00acee;
}
.tabs .tab-body .notifications , .tabs .tab-body .inbox {
margin: 1em 0 2em;
border: 1.5px solid #d4d4d4;
border-radius: var(--border-radius);
box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.2);
width: 100%;
display: flex;
flex-direction: column;
justify-content: space-between;
max-height: 90%;
overflow: scroll;
overflow-x: hidden;
}
.tabs .tab-body .inbox form {
height: 5rem;
display: flex;
align-items: center;
justify-content: center;
width: 100%;
padding: 0;
}
.tabs .tab-body .inbox form input {
width: 75%;
padding: 0.75rem;
box-sizing: border-box;
border-radius: var(--border-radius);
border-top-right-radius: 0;
border-bottom-right-radius: 0;
border: 1px solid #dddddd;
outline: none;
background: #eeeeee;
overflow: hidden;
transition: background 0.2s, border-color 0.2s;
}
.tabs .tab-body .inbox form input:focus {
border-color: var(--color-primary);
background: #ffffff;
}
.tabs .tab-body .inbox form button {
width: 3em;
padding: .6em;
background: #2196F3;
border-radius: var(--border-radius);
border-top-left-radius: 0;
border-bottom-left-radius: 0;
color: white;
font-size: 17px;
border: 1px solid var(--color-primary);
border-left: none;
cursor: pointer;
}
.tabs .tab-body .notifications .notifications__container , .tabs .tab-body .inbox .inbox__container {
margin: .5em;
padding: 1em;
display: flex;
justify-content: center;
align-items: center;
width: 100%;
height: auto;
cursor: pointer;
}
.tabs .tab-body .notifications .none, .tabs .tab-body .inbox .none {
cursor: default;
}
.tabs .tab-body .notifications .notifications__container .profilepic , .tabs .tab-body .inbox .inbox__container .profilepic {
width: 3.5rem;
height: 3.5rem;
background-position: center;
border-radius: 50%;
}
.tabs .tab-body .notifications .notifications__container .notifications__info__container {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.tabs .tab-body .notifications .notifications__container .notifications__info__container .notifications__info {
margin: 0 1em;
font: 500 1rem 'Quicksand', sans-serif;
}
.tabs .tab-body .notifications .notifications__container .notifications__info__container .date {
margin-top: .5em;
font-size: .8em;
color: grey;
}
.tabs .tab-body .notifications .notifications__divider , .tabs .tab-body .inbox .inbox__divider{
border: 1px solid #d4d4d4;
width: 99%;
}
And my JS is:
let tabHeader = document.getElementsByClassName("tab-header")[0];
let tabIndicator = document.getElementsByClassName("tab-indicator")[0];
let tabBody = document.getElementsByClassName("tab-body")[0];
let tabsPane = tabHeader.getElementsByTagName("div");
for(let i=0;i<tabsPane.length;i++){
tabsPane[i].addEventListener("click",function(){
tabHeader.getElementsByClassName("active")[0].classList.remove("active");
tabsPane[i].classList.add("active");
tabBody.getElementsByClassName("active")[0].classList.remove("active");
tabBody.getElementsByTagName("div")[i].classList.add("active");
tabIndicator.style.left = `calc(calc(100% / 2) * ${i})`;
});
}
var backtotopbutton = document.getElementById("topButton");
window.onscroll = function() {scrollFunction()};
function scrollFunction() {
if (document.body.scrollTop > 100 || document.documentElement.scrollTop > 100) {
backtotopbutton.style.display = "block";
} else {
backtotopbutton.style.display = "none";
}
}
document.addEventListener("DOMContentLoaded", () => {
const openMessages = document.getElementById("open_inbox");
const openNotifications = document.getElementById("open_notifications");
openMessages.addEventListener("click", function () {
tabHeader.getElementsByClassName("active")[0].classList.remove("active");
tabsPane[0].classList.add("active");
tabBody.getElementsByClassName("active")[0].classList.remove("active");
tabBody.getElementsByTagName("div")[0].classList.add("active");
tabIndicator.style.left = `calc(calc(100% / 2) * ${0})`;
});
openNotifications.addEventListener("click", function () {
tabHeader.getElementsByClassName("active")[0].classList.remove("active");
tabsPane[1].classList.add("active");
tabBody.getElementsByClassName("active")[0].classList.remove("active");
tabBody.getElementsByTagName("div")[1].classList.add("active");
tabIndicator.style.left = `calc(calc(100% / 2) * ${1})`;
});
});
$(document).ready(function(){
$('#topnav_button').click(function() {
$('.nav').toggle(200);
});
$('#open_inbox, #open_notifications').click(function() {
$('#navHeader').show(200);
});
$('#close_header_tabs').click(function() {
$('#navHeader').hide(200);
});
$('#topButton').click(function() {
$('body, html').animate({
scrollTop:0
},300);
});
});
Notifications div has a sql to project all notifs not included in this question to minimize code. It shows both the content of messages and notifications tab.
But when I added another line of div inside my messages tab: example:
<div class="inbox active" id="inbox">
<form action="includes/chatsearch-inc.php" method="POST">
<input type="text" name="search" placeholder="Search a user or applicant\'s name">
<button name="submit"><i class="fa fa-search"></i></button>
</form>
<div>
</div>
</div>
and click the notifications tab, the notifications tab doesn't show anything, as in a clear white.
I managed to check every bit of my css, but I can seem to see any thing wrong, am I missing something? Thanks!
EDIT: I now know where the problem is. The problem is when I click the notifications tab, it doesn't switch the active class in DOM from inbox to notifications, and doesn't remove the active class from inbox. Without the said content inside the inbox, it works flawlessly. Why is that?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Find the answer in similar questions on our website.
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.
PHP (from the English Hypertext Preprocessor - hypertext preprocessor) is a scripting programming language for developing web applications. Supported by most hosting providers, it is one of the most popular tools for creating dynamic websites.
The PHP scripting language has gained wide popularity due to its processing speed, simplicity, cross-platform, functionality and distribution of source codes under its own license.
https://www.php.net/
JavaScript is a multi-paradigm language that supports event-driven, functional, and mandatory (including object-oriented and prototype-based) programming types. Originally JavaScript was only used on the client side. JavaScript is now still used as a server-side programming language. To summarize, we can say that JavaScript is the language of the Internet.
https://www.javascript.com/
CSS (Cascading Style Sheets) is a formal language for describing the appearance of a document written using a markup language.
It is mainly used as a means of describing, decorating the appearance of web pages written using HTML and XHTML markup languages, but can also be applied to any XML documents, such as SVG or XUL.
https://www.w3.org/TR/CSS/#css
HTML (English "hyper text markup language" - hypertext markup language) is a special markup language that is used to create sites on the Internet.
Browsers understand html perfectly and can interpret it in an understandable way. In general, any page on the site is html-code, which the browser translates into a user-friendly form. By the way, the code of any page is available to everyone.
https://www.w3.org/html/
Welcome to the Q&A site for web developers. Here you can ask a question about the problem you are facing and get answers from other experts. We have created a user-friendly interface so that you can quickly and free of charge ask a question about a web programming problem. We also invite other experts to join our community and help other members who ask questions. In addition, you can use our search for questions with a solution.
Ask about the real problem you are facing. Describe in detail what you are doing and what you want to achieve.
Our goal is to create a strong community in which everyone will support each other. If you find a question and know the answer to it, help others with your knowledge.