将 CSS 属性添加到 jQuery

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5532076/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 19:19:36  来源:igfitidea点击:

Add CSS property to jQuery

jquerycss

提问by JD Audi

I need to set a CSS property in this script to go along with the animation, but I can't seem to do it right.

我需要在此脚本中设置一个 CSS 属性以配合动画,但我似乎无法正确设置。

I need the divwith ID of "container" to have a CSS property set when the click function is activated. I need an overflow: hiddenset to #container.

div当点击功能被激活时,我需要ID 为“容器”的 CSS 属性设置。我需要overflow: hidden一套#container

Here's my script.

这是我的脚本。

$(function() {
    $(".folderContent").hide();

    $(".signin").click(function(event) {
        var folderContent = $(".folderContent");


        var folderContentShown = folderContent.css("display") != "none";

        var clickedFolder = $(this);
        clickedFolder.parent("#signincontainer").after(folderContent);

        $("body").find("#container").not(clickedFolder).each(function() {
            if (!folderContentShown) $(this).not("#signincontainer").animate( {
                opacity: 0.50
            }, "slow");
            else $(this).animate({
                opacity: 1.00
            }, "slow");
        });

        //clickedFolder.animate({opacity: folderContentShown ? 1.00 : 0.70}, "fast");
        folderContent.slideToggle();
        event.preventDefault();
    });
});

回答by Damb

$('#container').css('overflow','hidden');

Did you try this?

你试过这个吗?

回答by trgraglia

You should just go to the jquery site and read it... it will make more sense and it is really straight forward.

你应该去 jquery 网站阅读它......它会更有意义,而且它真的很简单。

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

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

回答by kishan Radadiya

It's Simple to use:

使用很简单:

$("p").css("color", "red");

You can follow this link : DEMO

您可以点击此链接:DEMO

回答by Dostonbek Oripjonov

You can also add multiple attributes

您还可以添加多个属性

$('select_smth').css({
   'color' : 'red',
   'height' : '10px'
});