CSS 过渡 : Div does not move back to its original place

标签 css

在我的 style.css 中我有这段代码:

.box {
    transform-origin: left top;
}
.to-right {
    transform: translate(200px, 0px);
}

.to-left{
    transform: translate(-200px, 0px);
    background-color: yellow;
}

单击按钮时,具有框类的 div 会向右移动,这是应该的。单击另一个按钮时,它应该回到原来的位置。

正如您在我的代码中所见,向右移动和稍后向后移动的值是相同的 (200px)。然而,它并没有回到同一个空间,而是移到了更远的地方。

我想,问题可能是没有来源,我在盒子类中添加了一个。但问题依然存在。

为什么会这样?

编辑:

这是我的代码:

样式.css

.box {
    transform-origin: left top;
    position: absolute;
}
.to-right {
    transform: translate(200px, 0px);
}

.to-left{
    transform: translate(-200px, 0px);
    background-color: yellow;
}

.move {
    transition: all 1s ease-in-out;
}

div 的代码如下所示:

 <div class="box move" ng-class="{'box': boxClass == 1, 'to-right': boxClass == 2, 'to-left': boxClass == 3} ">

可能值得注意的是,div 放置在 Bootstrap 和 angularjs 应用程序中。

最佳答案

当点击按钮时,方框向右移动 { 转换:翻译(200px,0px); 当再次点击时,它应该移动到第一位。 { 转换:翻译(0px,0px); }

.to-right {
  transform: translate(200px, 0px);
}

.to-left{
  transform: translate(0px, 0px);
  background-color: yellow;
}

关于CSS 过渡 : Div does not move back to its original place,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41201231/

相关文章:

当元素未在列之间准确划分时,CSS 列无法正确堆叠元素

html - 背景图片在 Firefox 和 Chrome 中显示,但在 IE9 中不显示

javascript - 如何使用 select 标签的 title 属性删除选中的选项

html - 导致 Bootstrap div 向右溢出而不是换行

css - 有什么方法可以使用 svg (img) 裁剪图像吗?

jquery - 从 Twitter IE7 错误 Bootstrap

javascript - 通过注释掉 CSS 属性,使用 JavaScript 切换样式属性

javascript - 倾斜后 DIV 的位移

html - css transition 如何制作mouseout效果

html - 当父元素具有固定大小时,overflow auto 在子元素中不起作用