元素的不透明度

发布于 2024-12-04 00:53:33 字数 440 浏览 1 评论 0原文

我正在尝试通过 jQuery 设置元素的不透明度。

$('[class*="OtherFeatur"]').load(function(){
                    $(this).fadeTo(500, 0.5);
                });

不工作,但当我工作时

                $('[class*="OtherFeatur"]').fadeTo(0,0.5);
it will be affected. where is problem of first code? and which one is better ,set opacity by jQuery or CSS? how can I do it by css ,that all browser can show it?

I'm trying to set opacity of element by jQuery.

$('[class*="OtherFeatur"]').load(function(){
                    $(this).fadeTo(500, 0.5);
                });

is not working but when I do

                $('[class*="OtherFeatur"]').fadeTo(0,0.5);

it will be affected. where is problem of first code?
and which one is better ,set opacity by jQuery or CSS?
how can I do it by css ,that all browser can show it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

痕至 2024-12-11 00:53:33

如果您只想设置元素的不透明度,请使用 css 方法。

 $('[class*="OtherFeatur"]').css("opacity", 0.5);

If you want to just set the opacity of element then use css method.

 $('[class*="OtherFeatur"]').css("opacity", 0.5);
无妨# 2024-12-11 00:53:33

动画需要长于 0 毫秒,

您可以使用:

$('[class*="OtherFeatur"]').css({ opacity: 0.5 });

如果我没有误解 jquery 已经扩展了 CSS 上的不透明度规则,因此它适用于所有浏览器。

An animation need to be longer then 0ms

you can just use:

$('[class*="OtherFeatur"]').css({ opacity: 0.5 });

if Im not mistaking jquery has extended the opacity rule on the CSS so it applies on all browsers.

幸福不弃 2024-12-11 00:53:33

.load() - 从服务器加载数据并将返回的 HTML 放入匹配的元素中。

因此此函数适用于将数据从另一个资源加载到您选择的元素。

可能您需要页面加载事件:

$(document).ready(function() {
   $('[class*="OtherFeatur"]').fadeTo(0,0.5);
});

或者如果您加载一些数据,请首先在 .load() 方法中指定源。

$('[class*="OtherFeatur"]').load('mysource.html', function(){
                $(this).fadeTo(500, 0.5);
            });

在这种情况下,函数将在加载内容后被调用。

.load() - Load data from the server and place the returned HTML into the matched element.

So this function works for loading data from the another resource to the element you selected.

probably you need page load event:

$(document).ready(function() {
   $('[class*="OtherFeatur"]').fadeTo(0,0.5);
});

or if you loads some data, specify the source first in the .load() method.

$('[class*="OtherFeatur"]').load('mysource.html', function(){
                $(this).fadeTo(500, 0.5);
            });

in this case function will be invoked after loading the content.

甜扑 2024-12-11 00:53:33

你正在寻找的是

$(window).load(function() {
    $('[class*="OtherFeatur"]').fadeTo(0,0.5);
});

what you are looking for is

$(window).load(function() {
    $('[class*="OtherFeatur"]').fadeTo(0,0.5);
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文