如何在CSS和Javascript中为网格区域设置动画?

时间:2019-06-16 10:31:15

标签: javascript html css

如何将动画修改为Java修改后的网格。我有这个CSS定义:

#lt-container-grid {
    display: grid;
    grid-template-columns: 150px 1fr;
    grid-template-rows: 50px 40px auto auto 50px;
    grid-template-areas: "title title" "header header" "sidebar sidebar" "main main" "footer footer";
}

#lt-sidebar {
    padding: 0;
    background: #4f4e4a;
    grid-area: sidebar;
    color: #9c6c00;
    display: block;
    height: auto;
}

并且我正在通过对我的javascript文件执行此操作来动画#lt-sidebar

function manageMainPanel(x){
            x.classList.toggle("change");
            var width = screen.width;
            console.log("device width: "+width);
            if(width < 736){
                if(document.getElementById("lt-container-grid").style.gridTemplateRows === "50px 40px auto auto 50px"){
                    document.getElementById("lt-container-grid").style.gridTemplateRows = "50px 40px 0px auto 50px";
                    document.getElementById("lt-sidebar").style.display = "none";
                    document.getElementById("lt-sidebar").style.height = "0";
                    document.getElementById("lt-sidebar").style.transition = "all 2s";
                }else{
                    document.getElementById("lt-container-grid").style.gridTemplateRows = "50px 40px auto auto 50px";
                    document.getElementById("lt-sidebar").style.display = "block";
                    document.getElementById("lt-sidebar").style.height = "auto";
                    document.getElementById("lt-sidebar").style.transition = "all 2s";
                }...

在我的html上:

<div class="lt-data-toggle" onclick="manageMainPanel(this)">

enter image description here

1 个答案:

答案 0 :(得分:0)

您可以使用:

.sides {
  animation: 0.7s curtain cubic-bezier(.86,0,.07,1) 0.4s both;

  display: grid;
  grid-template-columns: 50vw 50vw;
}


@keyframes curtain {
  0% {
    grid-gap: 100vw; 
  }

  100% {
    grid-gap: 0;
  }
}