【发布时间】:2015-10-23 06:09:17
【问题描述】:
我有一个由 6 个块组成的网格。单击每个块时,块会展开并覆盖容纳块的容器。
第一个盒子(左上角)看起来不错,但是其他的盒子没有像块增长到容器宽度和高度的错觉,因为它从左上角开始。
理想情况下,盒子 2 和 5 应该从它们的中心展开,盒子 1、3、4 和 6 应该从它们的远角展开。这可能吗?如何实现?
我的created a JSFiddle 表明了我的问题。但是重现的代码在这里:
jQuery
$(".service-block").on("click", "a", function (e) {
e.preventDefault();
var block = $(this);
var blockOffset = block.offset();
var blockBackgroundColor = block.css("backgroundColor");
var container = $(".service-grid");
var containerOffset = container.offset();
// Create the popup and append it to the container
var popout = $("<div class='service-block-popup'>Test</div>");
popout.css({
"backgroundColor": blockBackgroundColor,
"position": "absolute",
"top": blockOffset.top,
"left": blockOffset.left
}).appendTo(container)
// Now animate the properties
.animate({
"height": container.height() + "px",
"width": container.width() + "px",
"top": containerOffset.top,
"left": containerOffset.left
}, 1500, function() {
//alert("done");
})
.on("click", function () {
popout.remove();
});
});
标记
<div class="service-grid">
<div class="row">
<div class="service-block">
<a href="#" class="box1">
<span class="title">Box 1</span>
</a>
</div>
<div class="service-block">
<a href="#" class="box2">
<span class="title">Box 2</span>
</a>
</div>
<div class="service-block">
<a href="#" class="box3">
<span class="title">Box 3</span>
</a>
</div>
</div>
<div class="row">
<div class="service-block">
<a href="#" class="box4">
<span class="title">Box 4</span>
</a>
</div>
<div class="service-block">
<a href="#" class="box5">
<span class="title">Box 5</span>
</a>
</div>
<div class="service-block">
<a href="#" class="box6">
<span class="title">Box 6</span>
</a>
</div>
</div>
</div>
CSS
*, *::after, *::before {
box-sizing: border-box;
}
.service-grid { width: 600px; }
.row {
overflow: hidden;
}
.service-grid .service-block a {
display: block;
height: 200px;
width: 200px;
text-align: center;
float: left;
}
.service-grid .service-block a > img {
display: block;
margin: 0 auto;
transition: all 100ms linear 0s;
}
.service-grid .service-block a > .title {
display: block;
font-family: Arial,Helvetica,sans-serif;
font-size: 2.2rem;
font-weight: bold;
line-height: 3.2rem;
margin-top: 20px;
text-transform: uppercase;
}
.box1 { background: red; }
.box2 { background: purple; }
.box3 { background: yellow; }
.box4 { background: orange; }
.box5 { background: green; }
.box6 { background: magenta; }
【问题讨论】:
-
你只有6个盒子?还是可以增加盒子的数量?
-
目前只有6个-可能会增加,我想考虑一下它可以增加。