jquery - CSS 过渡不适用于图像

标签 jquery html css web css-transitions

我已经为 div 元素创建了一个有效的过渡,但是,当我尝试将完全相同的方法应用于图像类时,它不起作用。它不是平稳地向左移动,而是向左跳。旋转变换动画有效,但左转动画无效。

.firstimg{
width: 5%;
cursor: pointer;
position: absolute;
    -webkit-transition: all 0.4s ease;
   -moz-transition: all 0.4s ease;
    -ms-transition: all 0.4s ease;
     -o-transition: all 0.4s ease;
        transition: all 0.4s ease;
}

.turnedimg{
width: 5%;
cursor: pointer;
/*left: 12% !important;*/
position: absolute;

-webkit-transform: rotate(90deg);
   -moz-transform: rotate(90deg);
    -ms-transform: rotate(90deg);
     -o-transform: rotate(90deg);
        transform: rotate(90deg);

    -webkit-transition: all 0.4s ease;
   -moz-transition: all 0.4s ease;
    -ms-transition: all 0.4s ease;
     -o-transition: all 0.4s ease;
        transition: all 0.4s ease;
}

我不明白为什么轮换有效但过渡无效。我怎样才能使动画工作?如果有人感兴趣,我正在通过 JQuery 调用它

$(".firstimg").toggleClass("turnedimg");

最佳答案

您的图像必须具有“左”的初始值

.firstimg{
width: 5%;
left: 0%;
cursor: pointer;
...

关于jquery - CSS 过渡不适用于图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40664705/

相关文章:

javascript - 如何根据增加/减少值制作仪表动画

css - 防止列表环绕图像

html - 纯 CSS 下拉菜单需要第二列

javascript - 如何在不解析/标记化的情况下使用 Javascript/jQuery 应用 CSS 字符串来检索属性值对?

javascript - 更改 iframe src

javascript - 滚动特定元素的进度条

c# - 在 Html 页面中使用 Javascript 调用 Wcf 服务

javascript - 如何在没有标签的地方添加标签?

css - 使用响应式视频和填充

jquery - 使用 $.getJson 从 LocalDrive 读取 Json 文件