【问题标题】:Why is my CSS transition ending abruptly on mouse-out?为什么我的 CSS 过渡在鼠标移出时突然结束?
【发布时间】:2012-05-22 05:58:46
【问题描述】:

我只是在测试几个 CSS 过渡(我是 CSS 的初学者)。所有的过渡都很顺利。但是在其中一个过渡中,当鼠标悬停完成时,过渡会顺利播放,并且一旦您将鼠标移出,它就会突然结束。在所有其他情况下,mouseover 和 mouseout 都可以正常播放。

过渡以这种方式结束的原因是什么?如何解决? (固定:感谢@Edwin)。 现在,请解释一下为什么它不做任何改变。

jsbin:http://jsbin.com/oposofhttp://jsbin.com/oposof/5(我关心的是第一个过渡“三角形”)。

  #container1 >  div.triangle {
     border-bottom: 80px solid red;
     border-left: 60px solid transparent; 
     border-right: 60px solid transparent;
      width: 0px;
      height: 0px;

    -webkit-transition: all 1.2s ease-in-out;

  }

  #container1 >  div.triangle:hover {
    border-top: 80px solid green;
    border-left: 60px solid transparent; 
    border-right: 60px solid transparent;
  }


  #container1 >  div.triangle:active {
    border-left: 80px solid blue; 
    border-right: 60px solid transparent;

  }



  #container2 > div.testt {
    color: red;
    -webkit-transition: all 1s ease-in-out;
  }

  #container2 > div.testt:hover {
    color:yellow;
  }

  #container3 >  div.circle {
    border-radius: 70px;
    width: 100px;
    height: 100px;
    background: red;
    -webkit-border-radius: 50px;

    -webkit-transition: all 1.2s ease-in-out;

  }

  #container3 >  div.circle:hover {
    -webkit-border-radius: 20px;
    -webkit-transform: rotate(-45deg);
  }

我用过-webkit-,所以上面的演示只适用于chrome和safari。添加了-moz- 现在,你也可以在Mozilla上测试它(希望在IE中也是如此)。 http://jsbin.com/oposof/5

【问题讨论】:

    标签: css css-transitions


    【解决方案1】:

    似乎突然性是由于默认情况下它在顶部没有边框,然后在悬停时它突然在顶部有边框。因此,在 mouseout 中,它所做的不是过渡,而是隐藏顶部边框,因为过渡时没有可参考的初始值。

    试试这个:

    #container1 >  div.triangle {
        border-bottom: 80px solid red;
        border-top: 0 solid green;
        border-left: 60px solid transparent; 
        border-right: 60px solid transparent;
        width: 0px;
        height: 0px;
    
       -webkit-transition: all 1.2s ease-in-out;
    }
    

    【讨论】:

    • 您必须定义过渡点,以防边框顶部从 0 到 80 像素。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-10-14
    • 2012-05-20
    • 2021-12-20
    • 2016-11-10
    • 2015-10-12
    • 2019-03-26
    • 1970-01-01
    相关资源
    最近更新 更多