简体   繁体   English

div的翻译会增加页面宽度

[英]div on translating increases page width

I need to translate multiple div one on top of each other such that each layer slides away.I used animate.css to for animation and used jquery to identify when the animation ends and to add a class to the container such that it hides hence it doesn't increase the page width. 我需要将多个div相互叠加以使每一层都滑开。我使用animate.css来制作动画,并使用jquery来识别动画何时结束,并向容器添加一个类以使其隐藏不会增加页面宽度。 But regardless the page width is still increases. 但是无论页面宽度还是增加。

I would also like to loop the animation. 我也想循环播放动画。

jsfiddle: http://jsfiddle.net/8qzvhxmu/ jsfiddle: http : //jsfiddle.net/8qzvhxmu/

HTML: HTML:

<div class="test animated "></div>
<div class="test1 animated  lightSpeedOut"></div>

CSS: CSS:

html,body
{
    height: 100%;
    width: 100%;
    margin: 0;
    padding: 0;
}

.test
{
    background-color: #323232;
    height: 100%;
    width: 100%;
    z-index: 1;
    position: absolute;

}

.test1
{
    background-color: #01c8c8;
    height: 100%;
    width: 100%;
    z-index: 4;
    position: absolute;

}

.hide
{
    display: none;
}

JQuery: JQuery的:

$(document).ready(function(){
    $('.test1').one('webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend',function()
    {
        document.querySelector('.test1').classList.add("hide");
    });
});

Add a container/wrapper to the elements you'd like to animate and disable it's overflow , so it wont enlarge. 将容器/包装器添加到要设置动画的元素中,并禁用其overflow ,因此它不会扩大。

Fiddle : http://jsfiddle.net/e62m6hfn/ 小提琴http : //jsfiddle.net/e62m6hfn/

HTML HTML

<div class="container">
    <div class="test animated"></div>
    <div class="test1 animated lightSpeedOut"></div>
</div>

CSS CSS

html, body {
    height: 100%;
    width: 100%;
    margin: 0;
    padding: 0;
}

.container {
    width: 100%;
    height: 100%;
    overflow: hidden;
    position: relative;
}

.test {
    background-color: #323232;
    height: 100%;
    width: 100%;
    z-index: 1;
    position: absolute;
}
.test1 {
    background-color: #01c8c8;
    height: 100%;
    width: 100%;
    z-index: 4;
    position: absolute;
}
.hide {
    display: none;
}

Update 更新

I created a Fiddle where the animation loops (independent of the number of items you want to animate). 我创建了一个小提琴,动画在其中循环播放(与要设置动画的项目数无关)。

The code might not be the cleanest, but it works. 该代码可能不是最干净的,但是可以工作。

Fiddle with looping: http://jsfiddle.net/e62m6hfn/2/ 带有循环的小提琴: http : //jsfiddle.net/e62m6hfn/2/

HTML HTML

<div class="container">
    <div class="test-animate  test"></div>
    <div class="test-animate  test1"></div>
</div>

CSS CSS

html, body {
    height: 100%;
    width: 100%;
    margin: 0;
    padding: 0;
}
.container {
    width: 100%;
    height: 100%;
    overflow: hidden;
    position: relative;
}
.test-animate {
    height: 100%;
    width: 100%;
    position: absolute;
}
.test {
    background-color: #323232;
}
.test1 {
    background-color: #01c8c8;
}
.bottom {
    z-index: -1;
}

jQuery jQuery的

function animate($el) {
    $el.addClass('animated  lightSpeedOut');
}

var elCounter = 0;

$(document).ready(function () {
    elCounter = $('.test-animate').length;
    animate($('.test-animate').eq(elCounter - 1));

    $('.test-animate').on('webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend', function () {
        elCounter = (elCounter > 1) ? elCounter-1 : $('.test-animate').length;
        $('.test-animate').removeClass('bottom');
        $(this).addClass('bottom');
        $(this).removeClass('animated  lightSpeedOut');
        animate($('.test-animate').eq(elCounter - 1));
    });
});

Try adding overflow: hidden; 尝试添加overflow: hidden; to html, body {} . html, body {}

html,body
{
    height: 100%;
    width: 100%;
    margin: 0;
    padding: 0;
    overflow: hidden;
}

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

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