gpt4 book ai didi

jquery - 从远 Angular 动画宽度/高度

转载 作者:太空狗 更新时间:2023-10-29 15:13:34 24 4
gpt4 key购买 nike

我有一个由 6 个方 block 组成的网格。单击每个 block 时, block 会展开并覆盖容纳 block 的容器。

第一个框(左上角)看起来不错,但其他框无法产生 block 增长到容器宽度和高度的错觉,因为它是从它们的左上角位置开始的。

理想情况下,框 2 和 5 应该从它们的中心展开,而框 1、3、4 和 6 应该从它们的远 Angular 展开。这可能吗?如何实现?

我已经 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; }

最佳答案

我要自己回答我的问题。这是一个简单的错误!

我没有在 .service-block-popup 上设置宽度/高度。所以它没有从目前的状态扩展。它应该是这样构造的:

// 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,
"width": block.outerWidth(),
"height": block.outerHeight()
}).appendTo(container)
/* .... */

实际操作:http://jsfiddle.net/hdq0x2s8/4/

关于jquery - 从远 Angular 动画宽度/高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33295844/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com