Skip to content

Commit

Permalink
Added Animation
Browse files Browse the repository at this point in the history
Added animation on mouse hover
  • Loading branch information
npmnishantsharma authored Mar 3, 2023
1 parent 5d0e4af commit 3bce1dc
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ function shadowizard(options) {
let images = document.querySelectorAll('.shadowizard');

if(options.shadow_type == 'hard'){
options.shadow_type = '0px'
}else{
options.shadow_type = '15px'
options.shadow_type = '0px';
} else {
options.shadow_type = '15px';
}

images.forEach(image =>{
image.style.boxShadow = `10px 10px ${options.shadow_type} 1px rgba(0,0,0,0.12)`;
if(options.padding){
image.style.padding = '1em'; // Added missing '=' operator
image.style.padding = '1em';
}
if(options.border){
image.style.border = '1px solid black';
Expand All @@ -31,7 +31,19 @@ function shadowizard(options) {
image.style.backgroundColor = options.background_color;
}
}
})

if(options.animation){ // check if animation property is set
image.style.transition = 'all 0.5s ease-in-out'; // add transition effect
image.addEventListener('mouseover', () => { // add mouseover event listener to trigger animation
image.style.transform = 'translateY(-5px)'; // move image up
image.style.boxShadow = `10px 15px ${options.shadow_type} 1px rgba(0,0,0,0.24)`; // change box shadow
});
image.addEventListener('mouseleave', () => { // add mouseleave event listener to reset animation
image.style.transform = 'translateY(0px)'; // move image down
image.style.boxShadow = `10px 10px ${options.shadow_type} 1px rgba(0,0,0,0.12)`; // reset box shadow
});
}
});
}

module.exports.shadowizard = shadowizard;

0 comments on commit 3bce1dc

Please sign in to comment.