jquery - 使用 jQuery css 显示 -webkit-transition

标签 jquery css css-transitions

我有

<div id="content"></div>

我正在使用 jQuery 进行样式设计

$('#content').css({'width': '10%', '-webkit-transition': '1s all'});

如何使用 jQuery css 使 -webkit-transition 工作

最佳答案

来自 MDN :

Formal syntax: [ none | <single-transition-property> ] || <time> || <timing-function> || <time>

Note that order is important within the items in this property: the first value that can be parsed as a time is assigned to the transition-duration, and the second value that can be parsed as a time is assigned to transition-delay.

所以你的语法错误,应该是all 1s但我不确定你为什么要用 jQuery 来做,而你可以用纯 CSS 来实现。

$('#content').css({'width': '10%', '-webkit-transition': 'all 1s'});
                                                        ---^---

开发人员使用 jQuery 来填补跨浏览器问题的空白,这里您使用的是特定于浏览器的属性,对于 jQuery 也是如此,没有意义。

如果您想使用纯 CSS,请使用

#content {
    -webkit-transition: all 1s;
    transition: all 1s;
}

关于jquery - 使用 jQuery css 显示 -webkit-transition,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23835479/

相关文章:

javascript - 如何将日期选择器的 HTML5 表单最小限制设置为 "Check-In Date (user input)"

javascript - 单击一个链接并调用另一个

html - Bootstrap 3.3.6 中的下拉菜单不起作用

jQuery:如何通过滑动交替显示和隐藏元素?

html - 在打开新页面时运行过渡效果

javascript - 如何在 rails 5.1.6 中使用 AJAX 上传图片

c# - 如何运行 jQuery 使用 HttpHandler

javascript - 坚持均匀调整图像动画大小

css - CSS 显示属性的过渡

javascript - 是否可以对 CSS 动画进行排队(示例)?