【问题标题】:reset transition when hover out悬停时重置过渡
【发布时间】:2014-01-24 16:52:16
【问题描述】:

当我将鼠标悬停在 div 上时,我希望重置 move.down 功能。 现在它没有重置,但只是再次移动回来。 对此主题的任何帮助都会非常感激。

见代码:

CSS

#box_1{
   border-radius:12px;
   display: block;
   position: relative !important;
   width: 204px;
   height: 203px;
   background:url(http://biready.visseninfinland.nl/wp-content/uploads/2014/01/input1.png);
   background-size:204px 203px;
   background-repeat:no-repeat;
}

#box_1 .hoverImg {
   position: absolute;
   left: 0; 
   top: 0;
   width: 204px;
   height: 203px;
   display: none;
}

#box_1:hover .hoverImg {
   display: block;
   width: 204px;
   height: 203px;
}

#axis1:hover .move-down {
   transform: translate(0,100px);
   -webkit-transform: translate(0,100px);
   -o-transform: translate(0,100px);
   -moz-transform: translate(0,100px);
}

.object1 {
   position: absolute;
   transition: all 5s ease-in;
   -webkit-transition: all 5s ease-in-out; /** Chrome & Safari **/
   -moz-transition: all 5s ease-in-out; /** Firefox **/
   -o-transition: all 5s ease-in-out; /** Opera **/
}

.object1 {
   position: absolute !important;
}
.line1 {
   top: 8%;
   left: 5%;
   width: 180px;
   height: 15px;
}

#box_1:hover .move-down {
   transform: translate(0,150px);
   -webkit-transform: translate(0,150px);
   -o-transform: translate(0,150px);
   -moz-transform: translate(0,150px);

}

HTML

<div id="box_1">
<div id="axis1"><img class="object1 line1 move-down" src="http://biready.visseninfinland.nl/wp-content/uploads/2014/01/balkje1.gif"/></div>
<div class="hoverImg"><img src="http://biready.visseninfinland.nl/wp-content/uploads/2014/01/input2-80.png" width="204" height="203" alt=""></div>
</div>

见小提琴:http://jsfiddle.net/38m6u/

期待回复。

【问题讨论】:

    标签: html css css-transitions reset


    【解决方案1】:

    当将鼠标悬停在#box_1 上时应该进行转换:

    .object1 中移除过渡并将其添加到选择器#box_1:hover .move-down

    UPDATED EXAMPLE HERE

    #box_1:hover .move-down {
        transform: translate(0, 150px);
        -webkit-transform: translate(0, 150px);
        -o-transform: translate(0, 150px);
        -moz-transform: translate(0, 150px);
        transition: all 5s ease-in;
        -webkit-transition: all 5s ease-in-out;
        -moz-transition: all 5s ease-in-out;
        -o-transition: all 5s ease-in-out;
    }
    

    【讨论】:

    • @ZachSaucier 它在 Chrome 上对我有用 - 很确定 OP 指的是在hover 上向下翻译元素的行。它几乎看不到,但它正在工作。
    • 这对我有用,如果我在一个 div 中有多个对象,这是否也有效。像 .object1、.object2 和 .object3?
    • @LaurensHoogland 是的,如果您使用的是课程,则应该这样做。在这种情况下.move-down.
    猜你喜欢
    • 2022-01-26
    • 2021-08-27
    • 2015-02-14
    • 1970-01-01
    • 2018-01-22
    • 2021-05-17
    • 2018-09-17
    • 1970-01-01
    相关资源
    最近更新 更多