I'm currently working on a project to develop a photo gallery.
let img = document.createElement('img')
img.src = "https://upload.wikimedia.org/wikipedia/commons/thumb/0/07/Wikipedia_logo_%28svg%29.svg/1250px-Wikipedia_logo_%28svg%29.svg.png"
// console.log(alldata[i].links[0].href)
let border = document.createElement('div')
border.appendChild(img)
border.className = 'gallery'
document.body.appendChild(border)
:root {
--wid: 300px;
}
.gallery{
background: grey;
width: var(--wid);
}
img{
height: 250px;
width: var(--wid);
}
img:hover {
transform: scale(1.5);
}
I'd like to achieve an effect where the image enlarges when a user hovers over it, but without altering its width. I've experimented with using transform: scale(1.5);
and zoom:150%
, both of which work fine; however, they result in the image's dimensions changing.
Is there a method to trigger a zoom-like effect that maintains the image's original width and height?
This website features a photo gallery showcasing a similar hover effect (the image slightly magnifies by around 110%).
Any feedback is greatly appreciated!