Reputation: 10179
I have some divs and have some effects on it thorugh jQuery. When I hover over a div it expands. But then the divs beside and beneath it move along with it. I want the same effect like the expandable user card given on stackoverflow after 1k repuration.
This is what I have done.
JS:
$(document).ready(function () {
var delay = 1000;
$(".user").hover(function () {
$(this).css("background-color", "#eee");
$(this).delay(delay).animate({
width: '350px',
height: '200px'
});
$(this).find("img").delay(delay).animate({
marginTop: '+=5px',
marginLeft: '+=5px'
});
}, function () {
$(this).css("background-color", "#fff");
$(this).delay(delay).animate({
width: '300px',
height: '50px'
});
$(this).find("img").delay(delay).animate({
marginTop: '-=5px',
marginLeft: '-=5px'
});
});
});
So in a nutshell:
.user
then the div should be expanded else nothing should happen. Upvotes: 1
Views: 3883
Reputation: 5213
This can be done purely in CSS3, and here's what you're looking for: Wrap each <div class="user">
in a <div class="userWrap">
. Then, use the following CSS:
.userWrap {
position: relative;
display: inline-block;
width: 300px;
height: 50px;
overflow: visible;
z-index: 1;
}
.userWrap:hover {
z-index: 2;
}
.user {
position: absolute;
width: 300px;
height: 50px;
margin-bottom: 5px;
background: #fff;
transition: width 0.3s, height 0.3s;
}
.user:hover {
width: 350px;
height: 200px;
background: #eee;
transition: width 0.3s ease 0.5s, height 0.3s ease 0.5s;
}
To achieve the desired effect.
Upvotes: 3