调整网站的所有文本和背景对比度(对比度交换器)ADA WCAG合规

Adjust All Text and Background For A Website For Contrast (Contrast Swapper) ADA WCAG Compliance

本文关键字:对比度 交换器 ADA 合规 WCAG 背景 网站 文本 调整      更新时间:2023-09-26

我正在建立一个高级友好的网站。我在页面顶部添加了一个按钮,删除所有背景颜色并将其更改为白色,然后将所有文本颜色更改为黑色,以提供一个不错的高级友好/视力受损的网站视图。基本上是想实现一个对比度交换器。我试着写一个jquery函数来实现这个结果。然而,经过几个小时的工作,我想出的功能是过于复杂,并没有提供我所希望的结果,因为有这么多的html元素可以在一个页面上。在jQuery或Javascript中是否有任何简单的方法来选择所有html元素并应用白色背景和黑色文本?如果有一种方法可以在CSS中做到这一点,也可以工作,但是结果必须是我可以重用的东西。我需要将此功能复制到500多个网站,而无需手动调整每个网站。

大多数页面在<html>标签上添加了一个类。所以你可以创建2个css一个带class,一个不带class。

示例:http://jsfiddle.net/7RVWG/

$('html *:not(script, style, noscript)').each(function() {
    $(this).css("background", "none");
    $(this).css("background-color", "yellow");
    $(this).css("color", "black");
    $(this).css("box-shadow", "none");
    $(this).css("text-shadow", "none");
});

我能够使用上面的jQuery代码来完成这一点,而不修改任何CSS。以上代码将背景更改为黄色,并将文本颜色更改为白色。你可以修改它们来完成不同的行为,例如,白色加黑色,黑色加白色,黑色加黄色。

import java.awt.*;
import javax.swing.*;
public class Test3 implements Icon
{
    public static final int NONE = 0;
    public static final int DECENDING = 1;
    public static final int ASCENDING = 2;
    protected int direction;
    protected int width = 8;
    protected int height = 8;
    public Test3(int direction)
    {
        this.direction = direction;
    }
    public int getIconWidth()
    {
        return width+1;
    }
    public int getIconHeight()
    {
        return height+1;
    }
    public void paintIcon(Component c, Graphics g, int x, int y)
    {
        Color bg = c.getBackground();
        Color light = bg.brighter();
        Color shade = bg.darker();
        int w = width;
        int h = height;
        int m = w / 2;
        if (direction == ASCENDING)
        {
            g.setColor(shade);
            g.drawLine(x, y, x + w, y);
            g.drawLine(x, y, x + m, y + h);
            g.setColor(light);
            g.drawLine(x + w, y, x + m, y + h);
        }
        if (direction == DECENDING)
        {
            g.setColor(shade);
            g.drawLine(x + m, y, x, y + h);
            g.setColor(light);
            g.drawLine(x, y + h, x + w, y + h);
            g.drawLine(x + m, y, x + w, y + h);
        }
    }
    public static void main(String[] args) 
    {
        Test3 t=new Test3(5);
        t.paintIcon(20,10,5,5);
    }
}