javascript - webkit 背景上的 Jquery.animate()

标签 javascript jquery jquery-animate

如何在 $(this) 上使用 Jquery 方法 .animate() 来实现以下目的:

background: -webkit-gradient(linear, left top, left bottom, from(#2d2d2d), to(#373737))

我尝试使用:

$(this).css("background", "-webkit-gradient(linear, left top, left bottom, from(#d70000), to(#679938))");

效果很好,但我想定义转换所需的时间

最佳答案

使用 jQuery animate 方法,如下所示:

$(this).animate({"background": "-webkit-gradient(linear, left top, left   bottom, from(#d70000), to(#679938))"}, 4000/* Your transition MS here, ex. 4000 */);

有关 animate 方法的更多信息,请单击 here.

如果你使用的是较低版本的 jQuery(嗯,这个方法是从 1.0.0 版本开始发布的,但有些版本可能不支持它),并且 animate 方法不起作用,那么这是一个替代方法:

$(this).delay(4000).css("background", "-webkit-gradient(linear, left top, left bottom, from(#d70000), to(#679938))");

关于javascript - webkit 背景上的 Jquery.animate(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39155213/

相关文章:

javascript - 如何获取 InDesign 中应用嵌套样式的文本

javascript - 使用 jquery 设置动画时如何避免兄弟元素摇晃

jquery - 基本的toggle()从下到上滑动问题

jquery - MaterializeCSS 滑出效果随着 JQuery load() 停止

jQuery 动画不播放

php - 如何在 php 中将选定的单选按钮值保留到下一页?

javascript - 如何使用 RxJS5 延迟重试发送 HTTP 请求?

javascript - 获取或发布请求返回快速响应?

jquery body委托(delegate)mouseover和mouseout同时触发

javascript - 对 Rails 4 如何使用 Paperclip 处理 AJAX 文件上传感到困惑