There is a container with images and scrollbar. My task is to scale image when hover event occurs. The snippet below demonstrates that.
The problem is cropping image on hover. If I remove the overflow
style, the crop is gone, but the container also lost the scrollbar.
How can I display a scaled image when hovering over the image without cropping and at the same time save scrollbar for the container?
img {
width: 28px
}
button:hover img {
cursor: pointer;
background-color: #3c3f43;
border-radius: 4px;
transform: scale(4.0)
}
<div id="container">
<div style="width: 300px; height: 50px;"></div>
<div style="overflow: auto; width: 200px; height: 50px">
<button><img src="https://cdn.betterttv.net/emote/6468f883aee1f7f4756770b5/3x"></button>
<button><img src="https://cdn.betterttv.net/emote/6468f883aee1f7f4756770b5/3x"></button>
<button><img src="https://cdn.betterttv.net/emote/6468f883aee1f7f4756770b5/3x"></button>
<button><img src="https://cdn.betterttv.net/emote/6468f883aee1f7f4756770b5/3x"></button>
<button><img src="https://cdn.betterttv.net/emote/6468f883aee1f7f4756770b5/3x"></button>
<button><img src="https://cdn.betterttv.net/emote/6468f883aee1f7f4756770b5/3x"></button>
<button><img src="https://cdn.betterttv.net/emote/6468f883aee1f7f4756770b5/3x"></button>
<button><img src="https://cdn.betterttv.net/emote/6468f883aee1f7f4756770b5/3x"></button>
<button><img src="https://cdn.betterttv.net/emote/6468f883aee1f7f4756770b5/3x"></button>
<button><img src="https://cdn.betterttv.net/emote/6468f883aee1f7f4756770b5/3x"></button>
<button><img src="https://cdn.betterttv.net/emote/6468f883aee1f7f4756770b5/3x"></button>
</div>
</div>
2
Answers
To display scaled images when hovering over the cursor without cropping and maintain the scrollbar for the container, you can make the following adjustments to your CSS:
allow the buttons to wrap to the next row when there isn’t enough
horizontal space.
the scrollbar using the calc function
Clone the image and set it
position: fixed;
. In the example below I use jquery: