Open Card Animation
How do I make an open card animation?
What is a open card animation? How do you make a open card animation? This script and codes were developed by Xavier Martínez on 31 October 2022, Monday.
Open Card Animation - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Open Card Animation</title> <link rel="stylesheet" href="css/style.css">
</head>
<body>
<div id="cardlist"></div> <script src="js/index.js"></script>
</body>
</html>
Open Card Animation - Script Codes CSS Codes
body { margin: 0; background-color: lightgrey; font-family: sans-serif;
}
#cardlist { max-width: 1200px; margin: 0 auto; display: flex; justify-content: space-around; flex-flow: row wrap;
}
.card { display: flex; align-items: center; justify-content: center; background-color: #536DFE; color: white; transition: opacity 0.4s ease-out, position 2s linear, left 1s ease, top 1s ease, margin 1s ease, background 0.4s ease, transform 1s linear, height 0.3s ease-in, width 0.3s ease-in;
}
.card:not(:focus):hover { cursor: pointer; background-color: white; color: #536DFE; box-shadow: inset 20px 0 0 -7px #536DFE, inset -20px 0 0 -7px #536DFE;
}
.card p { font-weight: normal; margin: 0;
}
.card p:hover { font-weight: bold;
}
Open Card Animation - Script Codes JS Codes
'use strict';
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var cardlist = document.getElementsByClassName('card');
var CARD = 'card';
var CARD_HEIGHT = 220;
var CARD_WIDTH = 330;
var CARD_MARGIN = 20;
var CARDLIST = 'cardlist';
var NUM_CARDS = 6;
var Card = function () { function Card(text) { var _this = this; _classCallCheck(this, Card); this.element = document.createElement('div'); //Class this.element.className = CARD; this.element.addEventListener('click', function (e) { return _this.openCard(e); }); //State this.state = 'closed'; //Let's define some subelements this.text = document.createElement('p'); this.text.innerHTML = text; this.element.appendChild(this.text); //Container document.getElementById(CARDLIST).appendChild(this.element); //Let's define some props //Size this.element.style.height = CARD_HEIGHT + 'px'; this.element.style.width = CARD_WIDTH + 'px'; //Margin this.element.style.margin = CARD_MARGIN + 'px'; } Card.prototype.openCard = function openCard(e) { var _this2 = this; this.state = 'animating'; this.element.style.backgroundColor = '#536DFE'; this.element.style.color = 'white'; this.element.style.pointerEvents = 'none'; var left = this.element.offsetLeft; var top = this.element.offsetTop; //Hide all cards, but not this one this.hideCards(); //Fix opened card setTimeout(function () { _this2.element.style.position = 'fixed'; _this2.element.style.left = left - CARD_MARGIN + 'px'; _this2.element.style.top = top - CARD_MARGIN + 'px'; //Remove card margins _this2.element.style.margin = '0px'; }, 1000); //Move the card to the top center setTimeout(function () { _this2.moveCard(); }, 1100); //Expand the card to fullwidth setTimeout(function () { _this2.expandCard(); }, 2000); }; Card.prototype.moveCard = function moveCard() { this.text.style.opacity = '0'; this.element.style.width = '120px'; this.element.style.height = '120px'; this.element.style.left = (window.innerWidth / 2 - 120 / 2).toString() + 'px'; this.element.style.top = '0px'; }; Card.prototype.expandCard = function expandCard() { var _this3 = this; document.getElementById('cardlist').style.flexWrap = 'nowrap'; this.element.style.position = 'initial'; this.element.style.width = '100vw'; this.element.style.height = '350px'; //Change text style to a bigger size setTimeout(function () { _this3.text.style.opacity = '1'; }, 500); this.text.style.fontWeight = 'bold'; this.text.style.fontSize = '40px'; }; Card.prototype.hideCards = function hideCards() { var _this4 = this; var _loop = function _loop(i) { if (cardlist[i] !== _this4.element) { cardlist[i].style.opacity = '0'; cardlist[i].style.pointerEvents = 'none'; setTimeout(function () { cardlist[i].style.display = 'none'; }, 2000); } }; for (var i = 0; i < cardlist.length; i++) { _loop(i); } }; return Card;
}();
//Init time!
for (var i = 0; i < NUM_CARDS; i++) { new Card('Text' + (i + 1));
}
![Open Card Animation - Script Codes](http://shots.codepen.io/xmjol/pen/vZVYgE-512.jpg)
Developer | Xavier Martínez |
Username | xmjol |
Uploaded | October 31, 2022 |
Rating | 3 |
Size | 4,603 Kb |
Views | 58,696 |
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 |
Article Header Collapse | 6,182 Kb |
React UI - 04 Steps Form | 4,906 Kb |
Locatifs-Info | 2,592 Kb |
React UI - 07 - Random Image Generator Giphy API | 4,193 Kb |
ReactJS Arrays | 2,631 Kb |
Let | 2,699 Kb |
React UI - 03 - CardList | 8,219 Kb |
A beautiful day | 2,973 Kb |
Background Styles | 3,501 Kb |
Flex Side-content | 2,952 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 |
Ghost | Mghayour | 11,738 Kb |
A Pen by Ash | Littleginger | 2,386 Kb |
Click Based Rotation Demo | Zeaklous | 2,086 Kb |
Simple DevTools | Deegill | 2,511 Kb |
Canvas Background Effect | Sonick | 3,513 Kb |
The Monty Hall Problem | Melatonind | 4,360 Kb |
A Pen by Bryan Rojas | Bryanrojas | 1,873 Kb |
Tumblr API | Juanv911 | 2,436 Kb |
Responsive Boxes without Images | Andymcfee | 4,120 Kb |
Scroll to view if element partially out of view port height | ChrisMaki | 2,104 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!