Image reveal on hover

Developer
Size
2,995 Kb
Views
6,072

How do I make an image reveal on hover?

What is a image reveal on hover? How do you make a image reveal on hover? This script and codes were developed by Mark Michon on 20 January 2023, Friday.

Image reveal on hover Previews

Image reveal on hover - Script Codes HTML Codes

<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Image reveal on hover</title> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/5.0.0/normalize.min.css"> <style> /* NOTE: The styles were added inline because Prefixfree needs access to your styles and they must be inlined if they are on local disk! */ section { margin: 3rem auto; width: 90vw; height: 90vh; transition: background-color .25s ease-in-out; position: relative;
}
ol { counter-reset: item; margin: 0; padding: 0;
}
li { display: inline-block; margin-left: 2em; font-size: 2em; line-height: 1.5;
}
li::before { content: counter(item,decimal-leading-zero); counter-increment: item; width: 2em; font-size: .5em;
}
img { position: absolute; top: center; left: 50%; margin-left: -300px; z-index: -1; opacity: 0; transition: opacity .5s ease-in-out;
}
.show { opacity: 1;
} </style> <script src="https://cdnjs.cloudflare.com/ajax/libs/prefixfree/1.0.7/prefixfree.min.js"></script>
</head>
<body> <section> <img src="https://unsplash.it/600/300/?image=1" alt="1" class="" /> <img src="https://unsplash.it/600/300/?image=2" alt="2" class="" /> <img src="https://unsplash.it/600/300/?image=3" alt="3" class="" /> <ol> <li data-color="red">Multi Word Project</li> <li data-color="blue">Singlename</li> <li data-color="green">Longer name than first</li> </ol>
</section> <script src="js/index.js"></script>
</body>
</html>

Image reveal on hover - Script Codes CSS Codes

section { margin: 3rem auto; width: 90vw; height: 90vh; transition: background-color .25s ease-in-out; position: relative;
}
ol { counter-reset: item; margin: 0; padding: 0;
}
li { display: inline-block; margin-left: 2em; font-size: 2em; line-height: 1.5;
}
li::before { content: counter(item,decimal-leading-zero); counter-increment: item; width: 2em; font-size: .5em;
}
img { position: absolute; top: center; left: 50%; margin-left: -300px; z-index: -1; opacity: 0; transition: opacity .5s ease-in-out;
}
.show { opacity: 1;
}

Image reveal on hover - Script Codes JS Codes

let items = document.querySelectorAll('li');
let section = document.querySelector('section');
let images = document.querySelectorAll('img');
const applyBackground = (color) => { section.style['background-color'] = color;
}
const clearBackground = () => { section.style['background-color'] = "";
}
items.forEach((item, i) => { let color = item.dataset.color; item.addEventListener('mouseenter', ()=> { // applyBackground(color); // console.log(images[i]); images[i].classList.add('show'); }) item.addEventListener('mouseleave', ()=> { clearBackground(); images[i].classList.remove('show'); })
})
Image reveal on hover - Script Codes
Image reveal on hover - Script Codes
Home Page Home
Developer Mark Michon
Username markmichon
Uploaded January 20, 2023
Rating 3
Size 2,995 Kb
Views 6,072
Do you need developer help for Image reveal on hover?

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!

Mark Michon (markmichon) Script Codes
Create amazing SEO content with AI!

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!