I’m creating an animated landing page using jQuery.
In the animation when the mouse is over a section of the image (which is sliced),
it pops out. Up till now I have been able to do this only if I set the sections’ positions to absolute. If they are not positioned absolute, they move once I enlarge and move out one of the sections.
Is there any way to get this effect without seting position to absolute?
Thank you!
Edit: This is the code I’m using
$(".block").mousemove(function () {
$(this).css("z-index", "1010");
$(this).stop().animate({
"width": "170px",
"height": "400px",
"top": "-12px",
"left": "-13px"
}, {
duration: 300,
easing: "swing",
queue: true
});
});
$(".block").mouseleave(function () {
$(this).stop().animate({
"width": "149px",
"height": "374px",
"top": "0px",
"left": "0px"
}, {
duration: 500,
easing: "swing",
queue: true,
complete: function () {
$(this).css("z-index", "1000");
}
});
});
A solution to your question could be this:
Right now each image is placed beside one another, right? Instead, try placing just white blocks beside one another as the placeholders to keep the dimensions and then place the images inside those boxes.
I don’t know your actual html code, but I can see you have six blocks in your example picture.
Below I have tried to set up a hover event on a very simple html box structure from the script you gave. In your script you had something about the
z-indexvalue and something to happen whencomplete. I have deleted that, since I couldn’t get the meaning of it or see it work withstop(), but you might edit this to match your wishes.Also I don’t use much
classorid, but that might be needed at a larger page.EDIT: Make sure your divs have the exact same dimensions as the image they contain.
HTML
CSS
Javascript
PS: Untested, but quite simple. You can give it a try.