gpt4 book ai didi

javascript - 动画期间布局中断

转载 作者:行者123 更新时间:2023-11-27 23:53:37 24 4
gpt4 key购买 nike

我正在做一个动画,所以当用户单击一个 div 时,它会替换为第一个 div,然后以一定宽度扩展,但它会破坏布局。如果我删除带有 class .title 的 div,一切正常,但当 div .title 存在时就不行了。

这是我的 fiddle :http://fiddle.jshell.net/p2fo4ek0/

<div class="internet_wrap">
<div class="internet tel" id="off_wrap">
<div class="package" id="one">
<div class="inner_package">
<div class="title">title</div>
</div>
</div>

<div class="package" id="two">
<div class="inner_package">
<div class="title">title</div>
</div>
</div>

<div class="package" id="three">
<div class="inner_package">
<div class="title">title</div>
</div>
</div>
</div>
</div>

    .internet {
text-align:center;
background: none repeat scroll 0% 0% rgba(248, 0, 140, 0.5);
padding-bottom:10px;
position: relative;
}

.internet .package {
display: inline-block;
/*border: 1px solid #FFFC00;*/
height: 60px;
width: 60px;
border-radius: 30px;
margin: 20px;
background:#fff;
color: rgba(0, 178, 248, 1);
position: relative;
cursor: pointer;
}

.inner_package {
display: inline-block;
width: 60px;
transition: all 2s ease-in;
background: #fff;
border-radius: 30px;
height: 60px;
}

var animating = false;

$('#off_wrap').on('click', '.package', function () {
if(!animating) {

var clickedDiv = $(this).closest('.package'),
prevDiv = $("#off_wrap > :first-child"),
distance = clickedDiv.offset().left - prevDiv.offset().left;

if (!clickedDiv.is(":first-child")) {
animating = true;
$.when(clickedDiv.animate({
left: -distance
}, 2000),
prevDiv.animate({
left: distance
}, 2000)).done(function () {
prevDiv.css('left', '0px');
clickedDiv.css('left', '0px');
//clickedDiv.css('width', $(window).width() - (clickedDiv.offset().left * 2));
clickedDiv.css('z-index', '100');
clickedDiv.css('overflow', 'visible');
clickedDiv.find(".inner_package").animate({width: 260}, 2000);

prevDiv.insertBefore(clickedDiv);
clickedDiv.prependTo("#off_wrap");
animating = false;
});
} else {
clickedDiv.css('z-index', '100');
clickedDiv.find(".inner_package").css('width', '260px');
}
}
});

最佳答案

尝试将此添加到“.internet .package”:

vertical-align: middle;

关于javascript - 动画期间布局中断,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25406130/

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