I want a div element to stretch across that is 33% width with a background image done in css
background-image:url(); background-size:cover
How do I animate a zoom-in of the image of the background in the div on mouseover or mouseneter, is there a plugin that can do this? The background div has to use background-size:cover because it's an elastic page.
I don't have a fiddle yet cos I don't know where or how to start
You can do something like this for webkit browsers.
Demo Here
Answer for those who wants to hack CSS transitioning zooming to get applied on background-size: cover;
-- if not, than read the second section for standard ways to achieve such effect
Demo (Using
background-size: cover;
to transition/zoom the element)As you said that transitioning the
cover
size is necessary, so I came up with the trick which I had told you previously, here I have a child element nested underposition: relative;
element where am having the child element set toposition: absolute;
withbackground-image
havingbackground-size
set tocover
and then onhover
of parent, I zoom in the element using thetransform: scale(2,2);
property.Also, a crucial thing while working with this solution is that we need to set the
z-index
of theposition: absolute;
element lower than what the elements you will be placing inside, so it will act like abackground
Answer for those who want to go clean with HTML and CSS
You cannot animate a
background-size
if it's value iscover
so either you will needpx
or%
, or you can also use animg
tag withtransform: scale(2,2);
property.Demo
Demo 2 (zoom-in or zoom-out from the center)
If you want to stick with
background-size: cover;
than you will have to wrap entire element inside a wrapper element having fixed dimensions withoverflow: hidden;
and than scale the child element onhover
of parent element.As you commented, for an
img
tag example, you can usetransform: scale(2,2);
to achieve that with the parent element set tooverflow: hidden;
Demo 2