javascript - 隐藏初始 3d 变换动画

标签 javascript css css-transforms

我已经设置了动画卡片翻转 jsfiddle单击按钮时发生。它使用 Modernizr 进行设置以测试该功能,然后在该功能可用时启用 3d 样式。如果你按下运行按钮,你会看到后面板在页面加载时旋转 180 度,有没有办法禁用它? 如果从一开始就设置样式,则不会发生这种情况,但我稍后会启用它们以实现兼容性(如果您在 javascript 中启用“&& false”,您将看到没有 3d 转换的浏览器的替代 View )。 HTML:

<div id="card-container">
    <button id="card-flip">Flip the card</button>
    <div id="card">
        <div class="front card-surface"><!-- front -->
            <p>The front</p>
        </div>
        <div class="back card-surface"><!-- back -->
            <p>The back</p>
        </div>
    </div>
</div>

Javascript:

if(Modernizr.csstransitions && Modernizr.csstransforms3d /* && false */ ){
    var flipButton = document.getElementById('card-flip');
flipButton.style.display = 'block';
    var cardContainer = document.getElementById('card-container');
    cardContainer.className = cardContainer.className + " threed";
    flipButton.addEventListener("click", flipfunction,false); // flipfunction toggles .flip class
}

CSS 在 jsfiddle 上

最佳答案

只有当父级 #card 元素具有 class='flip'.

在页面加载时,class='flip' 不会出现,因此效果不会应用。

更改代码从

.threed #card .card-surface{
    background-color:$base-white;
    -webkit-transition: all .3s ease-in-out;
    transition: all .3s ease-in-out;
    width: 280px;
    height: 180px;
    padding:10px;
}

.threed #card .front{ /* This is to apply the transition to the front element */
    background-color:$base-white;
    -webkit-transition: all .3s ease-in-out;
    transition: all .3s ease-in-out;
    width: 280px;
    height: 180px;
    padding:10px;
}
.threed #card.flip .back{ /* This is to apply transition to the back element only when parent has flip class */
    background-color:$base-white;
    -webkit-transition: all .3s ease-in-out;
    transition: all .3s ease-in-out;
    width: 280px;
    height: 180px;
    padding:10px;
}

Demo

关于javascript - 隐藏初始 3d 变换动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24719652/

相关文章:

javascript - 自定义CKEditor链接插件

css - 如何制作这个很酷的导航菜单

css - 我们如何仅使用 flex 来获得这样的布局?

Css 专注于出现的输入 div

html - 使用 z-index 和 translate3d 进行分层

javascript - Angular 6 - 循环遍历 Material 扩展面板内的 Material 表

javascript - 使用 Javascript 来调整包含最长内容的 2 个按钮的大小

css - 全屏 CSS3 "Cube"过渡

border - 将边框应用于 CSS 转换透视图像

javascript - 我的 react 路由器链接标签不会更改我的页面