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 |
Image Hover Zoom Effect | 2,052 Kb |
Fixed header | 3,802 Kb |
Responsive Mobile Menu | 3,267 Kb |
Fixed header jquery | 3,367 Kb |
Splash background image with text | 2,206 Kb |
Expandable Menu | 3,006 Kb |
Sliding side menu with icons | 2,357 Kb |
Filtering with shuffle.js | 2,712 Kb |
Sliding link on hover | 1,986 Kb |
Dropdown Menu on Image Click with Zoom | 2,639 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 |
Google Fonts Sass Mixin | HugoGiraudel | 4,237 Kb |
Lazy Load for Background Images | The_ruther4d | 2,977 Kb |
Nav Test -- cats 1 | Payls | 4,735 Kb |
ABVI Menu Discarded | Overdrivemachines | 3,607 Kb |
Classy Blockquote Styling | Andrewwright | 3,212 Kb |
Bloomberg Style Link Hover | Gil-- | 1,609 Kb |
SVG Transform vs CSS Transform | AmeliaBR | 4,175 Kb |
CSS Org Chart | Appirio-ux | 3,882 Kb |
Brent Burns Tribute Page | Nevada48 | 2,569 Kb |
Box Shadow Effects | Retrofuturistic | 2,143 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!