Expandable Boxes with pure JS
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 - 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>© 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'); } }
}
Developer | Deyan Dimitrov |
Username | deyand |
Uploaded | November 13, 2022 |
Rating | 3 |
Size | 2,844 Kb |
Views | 28,336 |
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!
Name | Size |
Expandable Boxes | 2,793 Kb |
Expandable Boxes with pure JS | 2,844 Kb |
Fixed header jquery | 3,367 Kb |
Sliding side menu with icons | 2,357 Kb |
A Pen by Deyan Dimitrov | 2,253 Kb |
Fullpage.js testing | 2,483 Kb |
Adaptive div height | 1,719 Kb |
Responsive Mobile Menu | 3,267 Kb |
Sliding link on hover | 1,986 Kb |
404 error bad TV page | 2,243 Kb |
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!
Name | Username | Size |
Add This API | ThatGuySam | 2,848 Kb |
Starfield using KineticJS | Asp | 3,512 Kb |
Polygon Dodecahedron in CSS | Vennsoh | 7,606 Kb |
CSS3 Latte Art Logo | Esambino | 2,036 Kb |
Basic 3D Fullscreen Transition | Apetrov | 3,270 Kb |
Table border-collapse property | Maxds | 1,672 Kb |
Responsive scrolling text | Ashdurham | 2,259 Kb |
Image grid with captions | Mchernin34 | 2,222 Kb |
Rrremark.com Overlay Highlighter | Derickruiz | 4,438 Kb |
LeMandinque | Aadesida | 9,046 Kb |
Surf anonymously, prevent hackers from acquiring your IP address, send anonymous email, and encrypt your Internet connection. High speed, ultra secure, and easy to use. Instant setup. Hide Your IP Now!