From bd5159c8b22f32bd1459951a8295e9188592be91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=84=E6=B3=89=E9=BE=99?= <3136621936@qq.com> Date: Mon, 29 Nov 2021 16:31:44 +0800 Subject: [PATCH] tij --- "\351\276\231/2021-11-17/demo01.html" | 58 ++++++++ "\351\276\231/2021-11-18/demo01.html" | 190 ++++++++++++++++++++++++++ "\351\276\231/2021-11-19/demo01.html" | 87 ++++++++++++ "\351\276\231/2021-11-19/demo02.html" | 185 +++++++++++++++++++++++++ "\351\276\231/2021-11-24/demo01.html" | 171 +++++++++++++++++++++++ "\351\276\231/2021-11-24/demo02.html" | 185 +++++++++++++++++++++++++ "\351\276\231/2021-11-25/demo01.html" | 99 ++++++++++++++ "\351\276\231/2021-11-25/demo02.html" | 30 ++++ "\351\276\231/2021-11-26/demo01.html" | 121 ++++++++++++++++ 9 files changed, 1126 insertions(+) create mode 100644 "\351\276\231/2021-11-17/demo01.html" create mode 100644 "\351\276\231/2021-11-18/demo01.html" create mode 100644 "\351\276\231/2021-11-19/demo01.html" create mode 100644 "\351\276\231/2021-11-19/demo02.html" create mode 100644 "\351\276\231/2021-11-24/demo01.html" create mode 100644 "\351\276\231/2021-11-24/demo02.html" create mode 100644 "\351\276\231/2021-11-25/demo01.html" create mode 100644 "\351\276\231/2021-11-25/demo02.html" create mode 100644 "\351\276\231/2021-11-26/demo01.html" diff --git "a/\351\276\231/2021-11-17/demo01.html" "b/\351\276\231/2021-11-17/demo01.html" new file mode 100644 index 0000000..6a14940 --- /dev/null +++ "b/\351\276\231/2021-11-17/demo01.html" @@ -0,0 +1,58 @@ + + + + + + Document + + + +
+
+ + \ No newline at end of file diff --git "a/\351\276\231/2021-11-18/demo01.html" "b/\351\276\231/2021-11-18/demo01.html" new file mode 100644 index 0000000..f78d59c --- /dev/null +++ "b/\351\276\231/2021-11-18/demo01.html" @@ -0,0 +1,190 @@ + + + + + + Document + + + +

white-space

+ +

word-break

+ +

word-wrap

+ +

word-spacing

+ +

letter-spacing

+ + + \ No newline at end of file diff --git "a/\351\276\231/2021-11-19/demo01.html" "b/\351\276\231/2021-11-19/demo01.html" new file mode 100644 index 0000000..28d613c --- /dev/null +++ "b/\351\276\231/2021-11-19/demo01.html" @@ -0,0 +1,87 @@ + + + + + + Document + + + + +

拖动滑块,改变RGB变量:

+

R:

+

G:

+

B:

+ + + \ No newline at end of file diff --git "a/\351\276\231/2021-11-19/demo02.html" "b/\351\276\231/2021-11-19/demo02.html" new file mode 100644 index 0000000..4ad4f6a --- /dev/null +++ "b/\351\276\231/2021-11-19/demo02.html" @@ -0,0 +1,185 @@ + + + + + + Document + + + + +
+

按钮文字颜色随着背景色自动变化实例页面

+ 回到相关文章 » +
+
+

效果:

+
+
+ +

拖动滑块,改变RGB变量:

+

R:

+

G:

+

B:

+
+
+
+
+

代码:

+
+
CSS代码:
+
+        :root {
+          /* 定义RGB变量 */
+          --red: 44;
+          --green: 135;
+          --blue: 255;
+          /* 文字颜色变色的临界值,建议0.5~0.6 */
+          --threshold: 0.5;
+          /* 深色边框出现的临界值,范围0~1,推荐0.8+*/
+          --border-threshold: 0.8;
+        }
+        
+        .btn {
+          font-size: 150%;
+          padding: .5em 2em;
+        }
+        .btn {
+          /* 按钮背景色就是基本背景色 */
+          background: rgb(var(--red), var(--green), var(--blue));
+        
+          /** 
+           * 使用sRGB Luma方法计算灰度(可以看成亮度)
+           * 算法为:
+           * lightness = (red * 0.2126 + green * 0.7152 + blue * 0.0722) / 255
+          */
+          --r: calc(var(--red) * 0.2126);
+          --g: calc(var(--green) * 0.7152);
+          --b: calc(var(--blue) * 0.0722);
+          --sum: calc(var(--r) + var(--g) + var(--b));
+          
+          --lightness: calc(var(--sum) / 255);
+          
+          /**
+           * --lightness近似看成亮度,范围0~1,此时,和临界值--threshold做比较:
+           * 大于,则正数,和-999999%相乘,会得到一个巨大负数,浏览器会按照合法边界0%渲染,也就是亮度为0,于是颜色是黑色;
+           * 小于,则和-999999%相乘,会得到一个巨大的正数,以最大合法值100%渲染,于是颜色是白色;
+          */
+          color: hsl(0, 0%, calc((var(--lightness) - var(--threshold)) * -999999%));
+          
+          /**
+           * 确定边框透明度。
+           * 如果亮度比--border-threshold值大,在说明按钮背景色比较淡,我们出现一个深色边框;
+           * 如果亮度比较小,说明按钮背景色较深,没有必要出现边框。
+             此时,--border-alpha计算后为负值,透明度小于0的时候,浏览器会按照0渲染,因此,边框透明。
+          */
+          --border-alpha: calc((var(--lightness) - var(--border-threshold)) * 100);
+          /* 设置边框相关样式 */
+          border: .2em solid;
+          border-color: rgba(calc(var(--red) - 50), calc(var(--green) - 50), calc(var(--blue) - 50), var(--border-alpha));
+        }
+                        
+
HTML代码:
+
<button class="btn">我是按钮</button>
+        
+        <p>拖动滑块,改变RGB变量:</p>
+        <p>R:<input type="range" min="0" max="255" value="44" name="red"></p>
+        <p>G:<input type="range" min="0" max="255" value="135" name="green"></p>
+        <p>B:<input type="range" min="0" max="255" value="255" name="blue"></p>
+
JS代码:
+
+        var eleRanges = document.querySelectorAll('input[type="range"]');
+        Array.from(eleRanges).forEach(function (range) {
+            range.addEventListener('input', function () {
+                document.documentElement.style.setProperty('--' + this.name, this.value);    
+            });
+        });
+                        
+
+
+
+
+ + + + + + \ No newline at end of file diff --git "a/\351\276\231/2021-11-24/demo01.html" "b/\351\276\231/2021-11-24/demo01.html" new file mode 100644 index 0000000..8a658b9 --- /dev/null +++ "b/\351\276\231/2021-11-24/demo01.html" @@ -0,0 +1,171 @@ + + + + + + Document + + + +
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ + \ No newline at end of file diff --git "a/\351\276\231/2021-11-24/demo02.html" "b/\351\276\231/2021-11-24/demo02.html" new file mode 100644 index 0000000..19a2b55 --- /dev/null +++ "b/\351\276\231/2021-11-24/demo02.html" @@ -0,0 +1,185 @@ + + + + + Document + + + +
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ + \ No newline at end of file diff --git "a/\351\276\231/2021-11-25/demo01.html" "b/\351\276\231/2021-11-25/demo01.html" new file mode 100644 index 0000000..b9bd7a6 --- /dev/null +++ "b/\351\276\231/2021-11-25/demo01.html" @@ -0,0 +1,99 @@ + + + + + + Document + + + +
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ + \ No newline at end of file diff --git "a/\351\276\231/2021-11-25/demo02.html" "b/\351\276\231/2021-11-25/demo02.html" new file mode 100644 index 0000000..0d88ceb --- /dev/null +++ "b/\351\276\231/2021-11-25/demo02.html" @@ -0,0 +1,30 @@ + + + + + + Document + + + +
+ + +
+ + \ No newline at end of file diff --git "a/\351\276\231/2021-11-26/demo01.html" "b/\351\276\231/2021-11-26/demo01.html" new file mode 100644 index 0000000..3811c5a --- /dev/null +++ "b/\351\276\231/2021-11-26/demo01.html" @@ -0,0 +1,121 @@ + + + + + + + + +
+
+
+
+
+
+
+
+
+
+
+
+
+ + \ No newline at end of file -- Gitee