Documentation
Webflow
Code
Setup: External Scripts
External Scripts in Webflow
Make sure to always put the External Scripts before the Javascript step of the resource.
In this video you learn where to put these in your Webflow project? Or how to include a paid GSAP Club plugin in your project?
HTML
Step 1: Copy structure to Webflow
Copy structure to Webflow
In the video below we described how you can copy + paste the structure of this resource to your Webflow project.
Copy to Webflow
Webflow structure is not required for this resource.
Step 1: Add HTML
HTML
<div class="example-card">
<div class="example-card__start">
<div class="new-badge__wrapper">
<div data-expiring-date="22/12/2024" class="new-badge"><span class="new-badge__span">New</span></div>
</div>
<h2 class="new-badge__h2">Show<br>New Badge</h2>
</div>
<div class="example-card__end"><img src="images/image-chair.jpg" loading="lazy" width="540" alt="Image of Chair" class="example-card__img"></div>
</div>
HTML structure is not required for this resource.
Step 2: Add CSS
CSS
.example-card {
background-color: #efeeec;
border-radius: 1.5em;
width: 30em;
height: 20em;
padding: 1.25em;
display: flex;
}
.example-card__start {
flex-flow: column;
justify-content: space-between;
align-items: flex-start;
width: 50%;
display: flex;
}
.example-card__end {
width: 50%;
}
.example-card__img {
object-fit: cover;
border-radius: .5em;
width: 100%;
height: 100%;
}
.new-badge {
background-color: #ff4c24;
border-radius: .25em;
padding: .3em .5em .25em;
display: none;
}
.new-badge__span {
color: #efeeec;
font-size: 18px;
font-weight: 500;
line-height: 1;
}
.new-badge__h2 {
text-transform: uppercase;
margin-top: 0;
margin-bottom: 0;
padding: .25em;
font-family: PP Neue Corp Tight, Arial, sans-serif;
font-size: 2.75em;
font-weight: 700;
line-height: .8;
}
Step 2: Add custom Javascript
Custom Javascript in Webflow
In this video, Ilja gives you some guidance about using JavaScript in Webflow:
Step 2: Add Javascript
Step 3: Add Javascript
Javascript
document.addEventListener("DOMContentLoaded", () => {
// Select all elements that have a data-expiring-date attribute
const elements = document.querySelectorAll('[data-expiring-date]');
// Get today's date at midnight (no timezone handling as requested)
const today = new Date();
// Normalize today to start of the day for consistent day-difference checks
today.setHours(0, 0, 0, 0);
elements.forEach(el => {
const dateStr = el.getAttribute('data-expiring-date'); // format D/M/YYYY
const [day, month, year] = dateStr.split('/').map(Number);
// Construct date object from attribute (month is zero-based in JS)
const publishedDate = new Date(year, month - 1, day);
publishedDate.setHours(0, 0, 0, 0);
// Calculate the difference in days
const diffInMs = today - publishedDate;
const diffInDays = diffInMs / (1000 * 60 * 60 * 24);
// Set display: block; if the published date is within the last 7 days (0 to 6 days ago)
if (diffInDays >= 0 && diffInDays < 7) {
el.style.display = 'block';
}
});
});
Step 3: Add custom CSS
Step 2: Add custom CSS
Custom CSS in Webflow
Curious about where to put custom CSS in Webflow? Ilja explains it in the below video:
CSS
Implementation
Add the published date to the attr
In the [data-expering-date]
attribute add the updated date, format it as: D/M/YYYY
Webflow
When the cards are connected with the CMS you can use Last published date as source for the attribute. This will automatically update the date. Make sure to select the correct format: D/M/YYYY
Resource Details
Last updated
January 22, 2025
Type
Osmo Basics
Category
Utilities & Scripts
Need help?
Join Slack