Skip to content

[js] 第625天 使用js写一个方法操作css变量 #3375

Open
@haizhilin2013

Description

@haizhilin2013
Collaborator

第625天 使用js写一个方法操作css变量

3+1官网

我也要出题

Activity

chaoing

chaoing commented on Feb 18, 2024

@chaoing

function changeColor() {

        const box = document.getElementById('myBox');

        const currentColor = getComputedStyle(box).getPropertyValue('--primary-color');

        const newColor = currentColor === 'blue' ? 'red' : 'blue';
        box.style.setProperty('--primary-color', newColor);
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    jsJavaScript

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @haizhilin2013@chaoing

        Issue actions

          [js] 第625天 使用js写一个方法操作css变量 · Issue #3375 · haizlin/fe-interview