Expandable Boxes with pure JS

Size
2,844 Kb
Views
28,336

How do I make an expandable boxes with pure js?

What is a expandable boxes with pure js? How do you make a expandable boxes with pure js? This script and codes were developed by Deyan Dimitrov on 13 November 2022, Sunday.

Expandable Boxes with pure JS Previews

Expandable Boxes with pure JS - Script Codes HTML Codes

<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Expandable Boxes with pure JS</title> <link rel="stylesheet" href="css/style.css">
</head>
<body> <html>
<body>	<div class="container">	<header>	<h1>Expandable Boxes</h1>	</header>	<section class="boxes-section">	<ul class="boxes-row">	<li class="box"><span>Box 1</span> </li>	<li class="box"><span>Box 2</span> </li>	</ul>	<ul class="boxes-row">	<li class="box"><span>Box 3</span> </li>	<li class="box"><span>Box 4</span> </li>	</ul>	<ul class="boxes-row">	<li class="box"><span>Box 5</span> </li>	<li class="box"><span>Box 6</span> </li>	</ul>	<ul class="boxes-row">	<li class="box"><span>Box 7</span> </li>	<li class="box"><span>Box 8</span> </li>	</ul>	</div>	</section>	<footer>	<p>&copy;&nbsp;created by <a href="http://deyand.com/en/portfolio">dido</a></p>	</footer>	</div><!-- end container-->
</body>
</html> <script src="js/index.js"></script>
</body>
</html>

Expandable Boxes with pure JS - Script Codes CSS Codes

*, *::after, *::before {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
margin: 0;
padding: 0;
}
.row::after, .row::before {
content: " ";
display: table;
}
/*--------
HTML BODY
--------*/
html{
height: 100%;
box-sizing: border-box;
font-size: 62.5%;
}
body {
font-family: Helvetica, Arial, Verdana,sans-serif;
margin: 0;
font-size:1.6rem;
line-height: 3rem;
color:#444;
}
.container{
width:90%;
margin:0 auto;
}
header{
width:100%;
margin:3em auto;
text-align:center;
}
/*----------
MAIN SECTION
------------*/
.boxes-section{
width:100%;
margin:0 auto;
position: relative;
}
.box{
display:block;
width:45%;
height:100px;
line-height:100px;
background-color:#fff;
border:1px solid #008ece;
float:left;
margin:1em 2%;
text-align:center;
color:#008ece;
cursor:pointer;
-webkit-transition: all .3s ease-in-out;
-moz-transition: all .3s ease-in-out;
-o-transition: all .3s ease-in-out;
-ms-transition: all .3s ease-in-out;
transition: all .3s ease-in-out;
}
.box.expanded {
background-color:#4a6570;
border-color: #4a6570;
color:#fff;
width: 94%;
height: 130px;
line-height:130px;
}
.box.clicked {
background-color:#008ece;
border-color: #008ece;
color:#fff;
width: 94%;
height: 130px;
line-height:130px;
}
/*-----
FOOTER
------*/
footer {
clear:both;
padding:10px 30px;
text-align:right;
color: #375757;
font-size: 14px;
height: 55px;
margin: 0 auto;
width: 100%;
}
footer a{
color:#4a6570;
text-decoration: none;
}
footer a:hover{
color: #006eaf;
outline: 0 none;
}

Expandable Boxes with pure JS - Script Codes JS Codes

window.onload = function() { function expBoxes(elem) { for (var i = 0; i < elem.length; i += 1) { elem[i].addEventListener("click", function(e) { var current = this; var siblings = allSiblings(this); if(current.classList.contains('expanded') && current.classList.contains('clicked')){ removeClass(siblings, 'expanded'); removeClass(siblings, 'clicked'); current.classList.remove('expanded', 'clicked'); } else if(current.classList.contains('expanded')){	//$('.box').not(box).classList.remove('expanded expanded clicked'); current.classList.add( 'clicked'); removeClass(siblings, 'clicked'); } else{ //	$('.box').not(box).classList.remove('expanded expanded clicked'); closeOpened(); addClass(siblings, 'expanded'); current.classList.add('expanded', 'clicked'); } }); };
}
expBoxes(document.getElementsByClassName('box')); //define sibling var allSiblings = function (el) { var skipMe = el; var siblings = []; el = el.parentNode.firstChild; do { if (el.nodeType == 1 && el != skipMe) siblings.push(el); } while (el = el.nextSibling); return siblings; }; //removeClass var removeClass = function(siblings, className) { for (var i = 0; i < siblings.length; i++){ siblings[i].classList.remove(className); } } //addClass var addClass = function(siblings, className) { for (var i = 0; i < siblings.length; i++){ siblings[i].classList.add(className); } } //closeOpened var closeOpened = function() { var exBox = document.getElementsByClassName('expanded'); for (var i = exBox.length-1; i >= 0; i--){ exBox[i].classList.remove('expanded', 'clicked'); } }
}
Expandable Boxes with pure JS - Script Codes
Expandable Boxes with pure JS - Script Codes
Home Page Home
Developer Deyan Dimitrov
Username deyand
Uploaded November 13, 2022
Rating 3
Size 2,844 Kb
Views 28,336
Do you need developer help for Expandable Boxes with pure JS?

Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!

Deyan Dimitrov (deyand) Script Codes
Create amazing marketing copy with AI!

Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!