2

如何在悬停时增加 div 大小?每个 div 都有相同的类名,它是动态创建的。我试过这段代码:

<script type="text/javascript">
$('.resultitem').bind('mouseover', function() {
    $(this).addClass('hovers');
    $('.resultitem').not('.hover').css({ opacity: 0.3 });
});
$('.resultitem').bind('mouseout', function() {
    $('.resultitem').removeClass('hovers').fadeTo('normal',1);
});
</script>

<style type="text/css">
.hovers {
    width:300px;
    height:400px;
}
img.hovers {
    width:300px;
    height:300px;
}
</style> 

它改变了其他div的对齐方式?

4

4 回答 4

12

使用 CSS3transform: scale(1.1)

.resultitem{
  width:150px;
  height:150px;
  background:#48e;
  -webkit-transition: 0.5s;
          transition: 0.5s;
}

.resultitem:hover{
  background:#59f;
  -webkit-transform: scale(1.1);
          transform: scale(1.1);
}
<div id="parent">
  <img class="resultitem" />
  <img class="resultitem" />
  <img class="resultitem" />
  <img class="resultitem" />
  <img class="resultitem" />
  <img class="resultitem" />
</div>

于 2013-04-03T10:02:11.970 回答
1

您是否有理由不使用纯 CSS?

jsFiddle

.sizeMe {
    width:300px;
    height:300px;
    background-color:#F00;
    opacity:0.3;
    /* use 'opacity 1s ease' for just opacity */
    -webkit-transition:all 1s ease;
    -moz-transition:all 1s ease;
    transition:all 1s ease;
}
.sizeMe:hover {
    height:400px;
    opacity:1;
}
于 2013-04-03T09:57:22.813 回答
1

试试这个jquery

$("#div1").hover(function () {
                $("#div1").addClass("divclass");
            }, function () {
                $("#div1").removeClass("divclass");
            });

html

           <div id="div1" >
            HTML borders are best created with CSS.
</div>

风格

<style>
.divclass{width:200px;height:100px;border:1px solid blue;}
</style>
于 2013-04-03T10:06:59.957 回答
0

使用 CSS

add $(this).addClass('resize');

.resize:hover {
    width:Xpx;
    height:Ypx
}
于 2013-04-03T09:58:35.590 回答