Can I apply a CSS transition to the overflow property?

后端 未结 5 1903
礼貌的吻别
礼貌的吻别 2020-11-28 14:04

I\'m trying to set a transition-delay to the overflow property of body when a div is clicked by adding a class to the

5条回答
  •  被撕碎了的回忆
    2020-11-28 15:02

    You can simulate a delay with animation:

    $("div").click(function() {
      $("body").addClass("no_overflow");
    });
    div {
      background: lime;
      height: 2000px;
    }
    
    .no_overflow {
      overflow: hidden;
      /* persist overflow value from animation */
      animation: 7s delay-overflow;
    }
    
    body {
      overflow: auto;
    }
    
    @keyframes delay-overflow {
      from { overflow: auto; }
    }
    
    
    I'm div

    You'll have to apply a separate animation to .body if you want a delay on removeClass, and also to take care that the two animations don't overlap or they'll cancel each other out.

提交回复
热议问题