Expanding/Shrinking a Div using JQuery and CSS
I am trying to use JQuery and CSS to allow users to navigate through a "wall" of different size images.
Basically, when a user hovers the mouse over an image, I want it to expand (which is currently working) and I would like the div to increase in width too, to show some additional information. For some rea开发者_如何学Cson, when I hover at this point, there is some really funky behavior, and when I mouseout, the image closes completely. I have a feeling I'm missing a "stop" in there somewhere, but I can't figure out where. Can someone take a look?
JQuery:
jQuery(function($){
$('.bar').mosaic({
animation : 'slide'
});
});
HTML:
<div class="MBT-CSS3">
<!--Bar-->
<div class="mosaic-block bar">
<a href="http://buildinternet.com/project/mosaic" target="_blank" class="mosaic-overlay">
<h4>This video is really cool! Click to watch more!</h4>
<p>by Media Innovation Team</p>
</a>
<!-- <img src="http://buildinternet.s3.amazonaws.com/projects/mosaic/mosaic.jpg"/> -->
<img src="img/grad1.png"/>
</div>
</div>
<div class="clearfix"></div>
CSS
.MBT-CSS3 div{
-webkit-transform:scale(0.7); /*Webkit 0.7 times the original Image size*/
-moz-transform:scale(0.7); /*Mozilla 0.7 times the original Image size*/
-o-transform:scale(0.7); /*Opera 0.7 times the original Image size*/
-webkit-transition-duration: 0.5s; /*Webkit: Animation duration*/
-moz-transition-duration: 0.5s; /*Mozilla Animation duration*/
-o-transition-duration: 0.5s; /*Opera Animation duration*/
/*opacity: 0.5;
z-index: 1;*/
position:relative;
overflow:hidden;
background-color:#000;
width: auto;
height: auto;
/*margin: 0 10px 5px 0; */
}
.MBT-CSS3 div:hover{
-webkit-transform:scale(1.1); /*Webkit: 0.5 times the original Image size*/
-moz-transform:scale(1.1); /*Mozilla 0.5 times the original Image size*/
-o-transform:scale(1.1); /*Opera 0.5 times the original Image size*/
/*box-shadow:0px 0px 30px gray;
-webkit-box-shadow:0px 0px 30px gray;
-moz-box-shadow:0px 0px 30px gray; */
opacity: 1;
z-index: 100;
width:600px;
/*height:250px; */
}
Thanks to anyone that might be able to help!!!! I really appreciate your time!
Try this :
$(document).ready(function(){
var busy = 0;
$('.MBT-CSS3').mouseover(function(){
if(!busy)
{
busy = 1;
$('#img').animate({
'-webkit-transform':'scale(1.1)',
'-moz-transform':'scale(1.1)',
'-o-transform':'scale(1.1)',
'opacity': '1',
'z-index': '100',
'width' : '600'
}, function(){busy = 0;});
}
});
$('.MBT-CSS3').mouseout(function(){
if(!busy)
{
busy = 1;
$('#img').animate({
'-webkit-transform':'scale(.7)',
'-moz-transform':'scale(.7)',
'-o-transform':'scale(.7)',
'opacity': '0.5',
'z-index': '1',
'width' : '300'
}, function(){busy = 0;});
}
});
});
Should work.I did add a id="img"
to the image you used. Hope this helps! You can add/remove/edit any of the attributes as you like.
Removed the whole .MBT-CSS3 :hover
part of your CSS as well.
Edited for the whole 'MBT-CSS3'
class, sorry :)
Your first problem is the :hover
. What happens is that the animation plays and you are no longer hovering over the element due to new dimentions/position. Thus hover is removed and the cycle repeats.
THanks so much for the help. I actually got it working by just setting the specific width and height of the initial div.
So whereas I did have:
position:relative;
overflow:hidden;
background-color:#000;
width: auto;
height: auto;
/*margin: 0 10px 5px 0; */
}
I changed it to:
position:relative;
overflow:hidden;
background-color:#000;
width: 350;
height: 250;
/*margin: 0 10px 5px 0; */
}
and it worked great. I really appreciate all of your time and help with this! You guys are awesome!
精彩评论