使用jQuery设置CSS3渐变属性? [英] Setting CSS3 gradient properties with jQuery?

查看:97
本文介绍了使用jQuery设置CSS3渐变属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在写一个依赖于CSS3渐变背景属性的插件。我没有问题得到这样的工作:

I'm writing a plugin that is reliant on CSS3 gradient background properties. I have no problem getting something like this to work:


$(this).css({ '-webkit-box-shadow': 'inset 2px 2px 5px #DEDEDE' });

但是,这无法正常工作:

However, this fails to work:


$(this).css({ 'background': '-webkit-gradient(linear,left top,left bottom,from(#f4f4f4),to(#FFFFFF))' });



我假设.css()使用浏览器支持的任何属性,

I was under the assumption that .css() worked with any property supported by the browser so I'm either setting it wrong with jQuery or this property isn't supported?

推荐答案

我怀疑第一个例子的工作原理:如果你想要设置css属性,你必须使用两个参数,如 $(this).css('background','-webkit-gradient(linear,left top,left bottom,from(#f4f4f4) ,至(#FFFFFF))');

I doubt the first example works either: if you want to set css property, you have to use two parameters, like $(this).css('background', '-webkit-gradient(linear,left top,left bottom,from(#f4f4f4),to(#FFFFFF))');​​​​​​​

有关主题的更多信息:

http://api.jquery.com/css/

More on the subject:
http://api.jquery.com/css/

编辑

您说得对,可以使用 {name:value} 符号,他们只是不在函数摘要中告诉它(你必须进一步阅读)。

无论如何,这里有两个参数(第二个从你的帖子)的工作示例: a href =http://jsfiddle.net/BX9Wa/ =nofollow noreferrer> http://jsfiddle.net/BX9Wa/

edit
You're right, it's possible to set css properties with {name:value} notation, they just don't tell it in the function summary (you have to read further on).
Anyway, here's the working example with two parameters (the second one from your post): http://jsfiddle.net/BX9Wa/

这篇关于使用jQuery设置CSS3渐变属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆