简体   繁体   English

单击时将div项目移动到div容器的顶部

[英]move div item on top of div container when being onclicked

! http://postimg.org/image/ym5xp7ilv/ http://postimg.org/image/ym5xp7ilv/

what i would like to achieve is to move the div item which is clicked on the top of the div container when each item is clicked...the rest of the items(those who are not being clicked) would fill the rest of the div container respectively 我要实现的是移动div项,当单击每个项时,将其单击在div容器的顶部...其余的项(未单击的项)将填充div的其余部分分别容器

HTML HTML

    <div class="row">
        <div class="col-md-12">
            <div class="containing_div">
                <div class="container_div"></div>
                <div class="menu_div">
                    <div class="item_div">Photos</div>
                    <div class="item_div">Video</div>
                    <div class="item_div">Music</div>
                    <div class="item_div">Files</div>
                    <div class="item_div">Contacts</div>
                </div>
            </div>
        </div>
    </div>

CSS CSS

.containing_div
{
  height: 100%;
}

.container_div
{
  background: #fff;
  height: 100%;
  width: 90%;
  box-shadow: 0 0 20px rgba(0, 0, 0, 0.3);
  text-align: center;
  font-family: "Open Sans";
  font-size: 26px;
  float: left;
  padding-top: 25px;
  position: relative;
}

.menu_div
{
  background: transparent;
  float: left;
}

.item_div
{
  background: #ddd;
  height: 80px;
  color: #bbb;
  font-family: "Open Sans";
  font-size: 16px;
  font-weight: 300;
  margin-bottom: 10px;
  text-align: center;
  padding: 8px;
  border-radius: 0 2% 2% 0;
  box-shadow: 0 0 3px rgba(0, 0, 0, 0.3);
  cursor: pointer;
  cursor: hand;
}

If I correctly understood what you desire, you can achieve your target with a little of jQuery, thanks to prependTo method. 如果我正确理解了您的需求,则可以使用prependTo方法,用一些jQuery来实现目标。

Here the working example and the jQuery function. 这里是工作示例和jQuery函数。

$('.item_div').on('click',function(){
    $(this).prependTo('.container_div');
});

UPDATE: 更新:

If you want to simply swap positions, here a variation. 如果您只想交换仓位, 这里是一个变体。

$('.item_div').on('click',function(){
    $(this).prependTo('.menu_div');
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM