This is a simple and subtle project that can be put in a resume, It will help gain good expression among the recruiters. Also, it is a good project for developers to practice. You can use it on websites and it will look amazing.
Fucky Notifications In HTML, CSS & JavaScript | User-Freindly Project |
Hello Everyone 👋 Welcome to My New Blog. Today I have made Funky Notifications with the help of HTML, CSS & Javascript 😍
I am Piyush, Sharing About Web development Daily. You can also check out me at @frontendeverything.
Let's start making this Funky Notification step by step.
Video of the project,
So that was the preview now let us start making the project 😄 First, we will code HTML then CSS & finally JS, and also I have shared codepen ink to make it easier for you.
HTML 🎈( step - 1)
In HTML we have made a div for the notification container and for like and dark buttons.
<div class="toggle__container">
<div class="toggle__label toggle__label--light">Light</div>
<div class="toggle"></div>
<div class="toggle__label toggle__label--dark">Dark</div>
</div>
<div class="card">
<div class="card__header">
<div class="title">
<div class="title__icon"></div>
<div class="title__wordmark">Funky Notifications</div>
</div>
<div class="action__container">
<button class="action action--like">
<svg class="action__icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
<path d="M20.84 4.61a5.5 5.5 0 0 0-7.78 0L12 5.67l-1.06-1.06a5.5 5.5 0 0 0-7.78 7.78l1.06 1.06L12 21.23l7.78-7.78 1.06-1.06a5.5 5.5 0 0 0 0-7.78z"></path>
</svg>
<div class="action__label">0</div>
</button>
</div>
</div>
<div class="card__body">Click the icon to generate a dynamic animation behind the notification.</div>
</div>
After the HTML we will design the buttons, containers and make it look amazing.
CSS🎈( step - 2)
html {
--gray-darkest: #24292e;
--gray-darker: #2f363d;
--gray-dark: #586069;
--gray-light: #959da5;
--gray-lighter: #e1e4e8;
--gray-lightest: #fafbfc;
--black: #000000;
--white: #FFFFFF;
--blue: #0AAFFF;
--purple: #7551E9;
--orange: #FF7D51;
--pink: #ED63D2;
--green: #2DCA73;
--yellow: #FFC212;
--bg: var(--gray-lighter);
--text-color: var(--gray-darkest);
--component-bg: var(--white);
--component-border: var(--gray-lighter);
}
html {
font-size: 62.5%;
box-sizing: border-box;
}
*, *:before, *:after {
box-sizing: border-box;
}
html, body {
height: 100%;
width: 100%;
}
body {
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;
background: var(--bg);
color: var(--text-color);
font-size: 2rem;
font-family: "Nunito Sans", system-ui;
line-height: 1.5;
padding-left: 1rem;
padding-right: 1rem;
}
.card {
background: var(--component-bg);
width: 100%;
max-width: 500px;
border-radius: 1.6rem;
border: 1px solid var(--component-border);
box-shadow: 0px 2px 5px rgba(0, 0, 0, 0.05), 0px 8px 16px rgba(0, 0, 0, 0.05);
position: relative;
margin-bottom: 2.4rem;
z-index: 1;
transition: all 0.2s ease-out 0s;
}
.card__header {
display: flex;
align-items: center;
justify-content: space-between;
padding-top: 2rem;
padding-bottom: 1rem;
}
.card__body {
padding-top: 1rem;
padding-bottom: 2rem;
}
.card__header, .card__body {
padding-left: 2rem;
padding-right: 2rem;
}
.title {
display: flex;
align-items: center;
}
.title__icon, .title__wordmark {
display: inline-block;
}
.title__icon {
width: 1.2em;
height: 1.2em;
background: var(--blue);
margin-right: 1rem;
border-radius: 5px;
}
.title__wordmark {
font-weight: 700;
}
.action {
cursor: pointer;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
text-align: center;
line-height: 1;
transition: all 0.1s ease-out 0s;
position: relative;
z-index: 200;
background: none;
border: 0;
}
.action:before {
content: "";
position: absolute;
background: var(--pink);
opacity: 0.2;
width: 0px;
height: 0px;
display: block;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
z-index: 100;
border-radius: 50%;
transition: all 0.2s ease-out 0s;
}
.action__icon {
width: 2rem;
height: 2rem;
color: var(--text-color);
}
.action__label {
font-size: 1.6rem;
color: var(--gray-light);
}
.action__container {
display: flex;
align-items: center;
justify-content: flex-end;
}
.action:hover, .action:focus {
color: var(--pink);
}
.action:hover:before, .action:focus:before {
width: 45px;
height: 45px;
transition: all 0.2s ease-out 0s;
}
.action:active, .action:focus {
outline: 0;
}
.action:active .action__icon, .action:focus .action__icon {
color: var(--pink);
fill: var(--pink);
}
.action:active .action__label, .action:focus .action__label {
color: var(--pink);
}
.animation {
z-index: 0;
position: fixed;
top: 50%;
left: 50%;
width: 480px;
height: 390px;
}
.animation__item {
width: 2rem;
height: 2rem;
position: absolute;
-webkit-animation: centerIn 1s ease-out forwards;
animation: centerIn 1s ease-out forwards;
}
@-webkit-keyframes centerIn {
from {
left: 50%;
top: 50%;
bottom: 50%;
right: 50%;
transform: translate(-50%, -50%) rotate(-315deg);
opacity: 1;
}
to {
transform: initial;
opacity: 0;
}
}
@keyframes centerIn {
from {
left: 50%;
top: 50%;
bottom: 50%;
right: 50%;
transform: translate(-50%, -50%) rotate(-315deg);
opacity: 1;
}
to {
transform: initial;
opacity: 0;
}
}
.toggle {
z-index: 2;
width: 4.5rem;
height: 1.5rem;
position: relative;
background: var(--black);
border-radius: 999px;
cursor: pointer;
display: inline-block;
margin: auto 1.5rem;
}
.toggle__label {
font-size: 1.2rem;
display: inline-block;
text-transform: uppercase;
letter-spacing: 0.0625em;
font-weight: 700;
}
.toggle__label--dark {
color: var(--gray-dark);
}
.toggle__label--light {
color: var(--gray-darkest);
}
.toggle:before {
position: absolute;
border-radius: 999px;
left: 0;
top: 50%;
transform: translate(-50%, -50%);
transform-origin: center;
content: "";
width: 2.25rem;
height: 2.25rem;
background: var(--gray-dark);
transition: all 0.2s ease 0s;
}
.toggle__container {
text-align: center;
margin: 0 auto 9rem auto;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
.toggle__container.active .toggle:before {
left: 100%;
}
.toggle__container.active .toggle__label--light {
color: var(--gray-dark);
}
.toggle__container.active .toggle__label--dark {
color: var(--gray-lightest);
}
Now we have done the CSS coding as well, now let's move to javascript. in javascript, we have not done enough coding. we have written for making buttons work.
JavaScript🎈( step - 3)
/// dribbble
let dribbbleLink = 'https://dribbble.com/ryanparag';
const dribbble = () => {
let styleRules = '<style> #dribbble { position: fixed; bottom: 15px; right: 15px;width: 100px;z-index: 100; } #dribbble a, #dribbble svg { display: block; } #dribbble svg{ width: 100%;fill: rgba(0, 0, 0, 0.25);} #dribbble svg:hover circle, #dribbble svg:focus circle{ fill: #ea4c89; } #dribbble svg:hover path, #dribbble svg:focus path{ fill: #C32361; }</style>';
let styleContainer = document.createElement('div');
styleContainer.innerHTML = styleRules;
document.head.appendChild(styleContainer);
let logoHTML = `
<a href=` + dribbbleLink + ` target="_blank">
<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32" fill="none">
<rect width="32" height="32" fill="black" fill-opacity="0"/>
<circle cx="16" cy="16" r="15.5"/>
<rect width="32" height="32" fill="black" fill-opacity="0"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M16 0C7.16703 0 0 7.16703 0 16C0 24.833 7.16703 32 16 32C24.8156 32 32 24.833 32 16C32 7.16703 24.8156 0 16 0ZM26.5683 7.37527C28.4772 9.70065 29.6226 12.6681 29.6573 15.8785C29.2061 15.7918 24.6941 14.872 20.1475 15.4447C20.0434 15.2191 19.9566 14.9761 19.8525 14.7332C19.5748 14.0738 19.2625 13.397 18.9501 12.7549C23.9826 10.7072 26.2733 7.75705 26.5683 7.37527ZM16 2.36009C19.4707 2.36009 22.6464 3.66161 25.0586 5.7961C24.8156 6.14317 22.7505 8.90239 17.8915 10.7245C15.6529 6.61171 13.1714 3.24512 12.7896 2.72451C13.8134 2.48156 14.8894 2.36009 16 2.36009ZM10.1866 3.64425C10.551 4.13015 12.9805 7.5141 15.2538 11.5401C8.86768 13.2408 3.22777 13.2061 2.62039 13.2061C3.50542 8.9718 6.36876 5.44902 10.1866 3.64425ZM2.32538 16.0174C2.32538 15.8785 2.32538 15.7397 2.32538 15.6009C2.9154 15.6182 9.54447 15.705 16.3644 13.6573C16.7636 14.4208 17.128 15.2017 17.4751 15.9826C17.3015 16.0347 17.1106 16.0868 16.9371 16.1388C9.89154 18.4121 6.14317 24.6247 5.8308 25.1453C3.6616 22.7332 2.32538 19.5228 2.32538 16.0174ZM16 29.6746C12.8416 29.6746 9.92625 28.5987 7.61822 26.7939C7.86117 26.2907 10.6377 20.9458 18.3427 18.256C18.3774 18.2386 18.3948 18.2386 18.4295 18.2213C20.3557 23.2017 21.1367 27.3839 21.3449 28.5813C19.6963 29.2928 17.8915 29.6746 16 29.6746ZM23.6182 27.3319C23.4794 26.4989 22.7505 22.5076 20.9631 17.5965C25.2495 16.9197 28.9978 18.0304 29.4664 18.1866C28.8764 21.987 26.6898 25.2668 23.6182 27.3319Z"/>
</svg>
</a>`;
let logo = document.createElement('div');
logo.id = 'dribbble';
logo.innerHTML = logoHTML;
document.body.appendChild(logo);
};
dribbble();console.clear();
// Like Button + increasing count
const likeButton = document.querySelectorAll('.action--like');
likeButton.forEach(button => {
button.addEventListener('click', () => {
const countNum = button.parentNode.querySelector('.action__label');
increaseVal(countNum);
animationItem();
button.style.transform = 'scale(1.2)';
const rotateDeg = getRange(10);
button.parentNode.parentNode.parentNode.style.transform = `rotate(${rotateDeg}deg)`;
setTimeout(() => {
button.style.transform = '';
button.parentNode.parentNode.parentNode.style.transform = '';
button.blur();
}, 300);
});
});
const increaseVal = target => {
var value = parseInt(target.innerHTML, 10);
value = isNaN(value) ? 0 : value;
value++;
target.innerHTML = value;
};
// Create Shape Animation
const colorClasses = ['blue', 'purple', 'orange', 'pink', 'green', 'yellow'];
const getRange = x => {
const val = Math.floor(Math.random() * x);
return val;
};
const animationItem = () => {
const newContainer = document.createElement('div');
const randomRotate = getRange(360);
newContainer.classList = 'animation';
newContainer.style.transform = `translate(-50%,-50%) scale(1.5) rotate(${randomRotate}deg)`;
// Random positioning of each shape
function randomPos(a) {
a.style.top = `${getRange(100)}%`;
a.style.right = `${getRange(100)}%`;
a.style.left = `${getRange(100)}%`;
a.style.bottom = `${getRange(100)}%`;
}
// Random number of shapes generated
const maxNumberOfItems = 20;
const minNumberOfItems = 10;
const randomNumberOfItems = Math.floor(Math.random() * maxNumberOfItems + minNumberOfItems);
for (var i = 0; randomNumberOfItems > i; i++) {if (window.CP.shouldStopExecution(0)) break;
// Random 0 - 4, generate circle, triangle, square, heart, star
let randomShapeNumber = getRange(4);
let randomClassNumber = getRange(6);
const newItem = document.createElement('div');
newItem.classList = 'animation__item';
randomPos(newItem);
if (randomShapeNumber == 0) {
newItem.innerHTML = `
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="var(--${colorClasses[randomClassNumber]})" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
<circle cx="12" cy="12" r="10"></circle>
</svg>`;
} else if (randomShapeNumber == 1) {
newItem.innerHTML = `
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="var(--${colorClasses[randomClassNumber]})" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
<path d="M20.84 4.61a5.5 5.5 0 0 0-7.78 0L12 5.67l-1.06-1.06a5.5 5.5 0 0 0-7.78 7.78l1.06 1.06L12 21.23l7.78-7.78 1.06-1.06a5.5 5.5 0 0 0 0-7.78z"></path>
</svg>`;
} else if (randomShapeNumber == 2) {
newItem.innerHTML = `
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="var(--${colorClasses[randomClassNumber]})" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
<rect x="3" y="3" width="18" height="18" rx="2" ry="2"></rect>
</svg>`;
} else if (randomShapeNumber == 3) {
newItem.innerHTML = `
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="var(--${colorClasses[randomClassNumber]})" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
<polygon points="12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2"></polygon>
</svg>
`;
} else {
newItem.innerHTML = `
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="var(--${colorClasses[randomClassNumber]})" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
<path d="M10.29 3.86L1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z"></path>
</svg>`;
}
newContainer.appendChild(newItem);
}window.CP.exitedLoop(0);
document.body.appendChild(newContainer);
setTimeout(() => {
newContainer.remove();
}, 1100);
};
// Toggle theme
const toggle = document.querySelector('.toggle');
const toggleContainer = document.querySelector('.toggle__container');
const root = document.documentElement;
toggle.addEventListener('click', function () {
if (toggleContainer.classList.contains('active')) {
toggleContainer.classList.remove('active');
root.style.setProperty('--bg', `var(--gray-lighter)`);
root.style.setProperty('--text-color', `var(--gray-darkest)`);
root.style.setProperty('--component-bg', `var(--white)`);
root.style.setProperty('--component-border', `var(--gray-lighter)`);
} else {
toggleContainer.classList.add('active');
root.style.setProperty('--bg', `var(--gray-darker)`);
root.style.setProperty('--text-color', `var(--gray-lightest)`);
root.style.setProperty('--component-bg', `var(--gray-darkest)`);
root.style.setProperty('--component-border', `var(--gray-darkest)`);
}
});
All the coding part is done, now let us see the final output, and also below I have mentioned the codepen link.
Final Output
The codepen link is here for making your work easier!
creator of this project:
.
.
If you found any value in this blog you can support me buy me a coffee.
.
.
.
.
Thank You For Scrolling Till here 😊. If You gain any knowledge then do checkout me at @frontendeverything. I am Piyush 🎉 I provide Content related to programming, technology, web development Daily.
.