Solved

Zoom on background image in div on hover

Posted on 2014-02-10
4
4,137 Views
Last Modified: 2014-02-11
Hi,

I have a dive with a background-image in it. When the user hovers over it I want to add some blur tot he image and zoom in on it slightly.

I have seen this effect on another wbesite but am failing to find it at the moment

I have tried using scale in the css but this enlarges the whole div. I would preferrably like to just zoom (enlarge and animate) the background image only retaining the div size.

Could anyone help me please?
0
Comment
Question by:flynny
  • 2
  • 2
4 Comments
 
LVL 8

Expert Comment

by:Adrian Crabtree
Comment Utility
Hi flynny,

I've set up an example using only CSS. You can view it here: http://jsfiddle.net/vCn25/3/.

If you go this route, it will not work for older browsers (IE8 and below). But as you can see, I set the background div within a wrapper. I did this so you could still have content within the wrapper without it getting blurred.
0
 

Author Comment

by:flynny
Comment Utility
Hi,

many thanks for that that would work brilliantly. However I ran into some problems.

Because I am trying to add this on a wordpress installation I want to create the divs with these effects dynamically.

The easiest way I saw to to this was

<div class="image-wrapper">
<img src="<?php echo get_post_meta($current_page->ID, 'thumb', true); ?>"/>	
</div>

Open in new window


with the following css

.image-wrapper {
    overflow: hidden;
    position: relative;
    height: 150px;
    width: 225px;
}

.image-wrapper img { 
	position:relative;
	z-index:0;
	margin-left: auto;
    	margin-right: auto;
    	-webkit-transition: all .5s ease-in-out;
       	-moz-transition: all .5s ease-in-out;
        -ms-transition: all .5s ease-in-out;
        -o-transition: all .5s ease-in-out;
        transition: all .5s ease-in-out;
}

.image-wrapper:hover img {

	width:300px;
	margin-left: auto;
	margin-right: auto;
    	-webkit-filter: blur(40px);
       	-moz-filter: blur(40px);
        -ms-filter: blur(40px);
        -o-filter: blur(40px);
}

Open in new window


however its not animating. My idea was to centre the image and then just increase the size.

The problem I am getting is that the image is just changing to the new size and is not being centered?
0
 
LVL 8

Accepted Solution

by:
Adrian Crabtree earned 500 total points
Comment Utility
Sorry for the last response! If you have your markup like that, you can try this: http://jsfiddle.net/vCn25/4/.

What I did here was give the <img> a specific width and height, and once you hover over the wrapper the width and height of the <img> increases. I was able to center the image by using position absolute and then adjusting the margins and the left and top properties.
0
 

Author Closing Comment

by:flynny
Comment Utility
perfect adrian many thanks for helping me out.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now