使用 CSS 放大 div,单击时删除同一父级下的其他 div



jQuery上的.animate给我带来了麻烦,所以我想在没有它的情况下调整div的大小。

我希望使用 CSS 放大盒子。我有 4 个相邻的框,当单击其中一个框时,它应该会放大,而其余的框会移出屏幕(可能所有左侧的框都向左移动,右侧的所有框向右移动)。这些框位于一个矩形中,应放大为wel。

我认为这可以通过在CSS中创建一个新类(.thumb:click)来完成,但是如何使用Javascript/HTML来执行放大和推离屏幕?

.HTML:

            <div class="portItem">
                     <div class="itemContent-wrap">
                          <div class="itemContent">
                              <div class="container">
                                  <div class="thumbWrap">
                                      <div class="thumb"></div>
                                      <div class="thumb"></div>
                                      <div class="thumb"></div>
                                      <div class="thumb"></div>
                                  </div>
                              </div>
                          </div>
                     </div> 
            </div>

.CSS:

.itemContent-wrap {
  display: inline-block;
  width: 100%;
  height: auto;
  margin-bottom: 10px;
}

.itemContent {
  height: 250px;
  width: auto;
  position: static;
  display: block;
  background: #ffffff;
  box-shadow: 1px 0px 20px black;
  margin-bottom: 10px;
  margin-left:-12.5%;
  margin-right:-12.5%;
  overflow-y: hidden;
}
.container {
    width: 110%;
    margin: 0 auto;
    background: transparent; 
    position: relative;
}
.thumbWrap {
  height: 220px;
  white-space: nowrap;
  width: 2000px;
}
.thumb {
  height: 200px;
  width: 450px;
  position: relative;
  display: inline-block;
  background: #D0E182;
  margin-top: 25px;
  margin-right: 5px;
}
//my guess...
.thumb:click {
}

Javascript(在使用.animate时...想避免这种情况)

$(document).ready(function(){
   $('.thumb').click(function()
   {
      $('.itemContent').css("cursor","pointer");
      $('.itemContent').animate({height: "500px"}, 'slow');
      $(this).animate({width: "900px",height:"400px"}, 'slow');
   });
$('.thumb').mouseout(function()
  {   
      $('.itemContent').animate({height: "250px"}, 'slow');
      $(this).animate({width: "450px",height:"200px"}, 'slow');
   });
});

JSFiddle: http://jsfiddle.net/g4GFb/

提前谢谢你!

CSS中不存在用于:click行为的内容。所以你用 JS/HTML 做对了。我会建议这个关于jQuery向左/向右滑动的tuto:

http://www.learningjquery.com/2009/02/slide-elements-in-different-directions

此外,我会添加一个 .active 类来帮助您为所有div 编写全局函数

希望这有帮助 ?

最新更新