css var all in one

number


  1. :root{
  2. --num: 0;
  3. }
  4. html{
  5. --num: 0;
  6. }

  1. let html = document.querySelector(`html`);
  2. html.style.setProperty(`--num`, `${angle}deg`);

demo

OK

https://codepen.io/xgqfrms/pen/JQVPzx

  1. /* :root{
  2. --num: 30;
  3. } */
  4. html{
  5. /* --num: 30; */
  6. --num: 30deg;
  7. }
  8. .box{
  9. display: flex;
  10. align-items: center;
  11. justify-content: center;
  12. width: 50vw;
  13. height: 50vh;
  14. background: #ccc;
  15. color: #0f0;
  16. margin: 10vh auto;
  17. transform: rotate(var(--num));
  18. /* transform: rotate(var(--num)deg); */
  19. }

  1. // https://developer.mozilla.org/en-US/docs/Web/API/Element/setAttribute
  2. let log = console.log;
  3. let html = document.querySelector(`html`);
  4. let root = document.querySelector(`:root`);
  5. log(`html =`, html);
  6. let angle = 30;
  7. let uid = setInterval(() => {
  8. angle += 30;
  9. html.style.setProperty(`--num`, `${angle}deg`);
  10. // html.setProperty(`--num`, `${angle}deg`);
  11. // html.setAttribute(`--num`, `${angle}deg`);
  12. // root.setAttribute(`--num`, 30);
  13. }, 1000);
  14. setTimeout(() => {
  15. clearInterval(uid);
  16. }, 1000 * 10);

style.setProperty

style.setProperty(propertyName, value, priority);

https://developer.mozilla.org/en-US/docs/Web/API/CSSStyleDeclaration/setProperty


  1. style.setProperty(propertyName, value, priority);

  1. let declaration = document.styleSheets[0].rules[0].style;
  2. declaration.setProperty('border-width', '1px 2px');
  3. // Equivalent to:
  4. // declaration.borderWidth = '1px 2px';

html & root & :root


  1. let root = document.documentElement;
  2. root.addEventListener("mousemove", e => {
  3. root.style.setProperty('--mouse-x', e.clientX + "px");
  4. root.style.setProperty('--mouse-y', e.clientY + "px");
  5. });

https://css-tricks.com/updating-a-css-variable-with-javascript/

html & :root


  1. let html = document.querySelector(`:root`);
  2. html.scrollHeight;
  3. html.innerText = html.innerText.split(' ').join('');

how to change css variables in javascript

https://davidwalsh.name/css-variables-javascript


  1. :root {
  2. --my-variable-name: #999999;
  3. }

  1. getComputedStyle(document.documentElement).getPropertyValue('--my-variable-name'); // #999999
  2. document.documentElement.style.setProperty('--my-variable-name', 'pink');

https://stackoverflow.com/questions/41370741/how-do-i-edit-a-css-variable-using-js

style.cssText

  1. var html = document.getElementsByTagName('html')[0];
  2. html.style.cssText = "--main-background-color: red";

style.setProperty

  1. var html = document.getElementsByTagName('html')[0];
  2. html.style.setProperty("--main-background-color", "green");

.setAttribute("style", "--main-background-color: green");

  1. var html = document.getElementsByTagName('html')[0];
  2. html.setAttribute("style", "--main-background-color: green");

touch circle menu

refs



xgqfrms 2012-2020

www.cnblogs.com 发布文章使用:只允许注册用户才可以访问!


css var all in one & html & root & :root的更多相关文章

  1. CSS3 & CSS var & :root

    CSS3 & CSS var & :root How to change CSS :root color variables in JavaScript https://stackov ...

  2. ssh服务启动失败 /var/empty must be owned by root and not group or world-writable.

    输入 /etc/rc.d/init.d/sshd start 启动sshd服务,报如下错误: /var/empty must be owned by root and not group or wor ...

  3. centos无法正常启动,报chown: invalid user:'root:root'

    现象: 系统无法正常启动,启动界面卡在上图的位置 注意错误信息:chown: invalid user:'root:root' 原因:/etc/passwd文件损坏或者被清空 尝试:1.grub菜单项 ...

  4. css var & auto width css triangle

    css var & auto width css triangle https://codepen.io/xgqfrms/pen/PooeEbd css var https://codepen ...

  5. 0 lrwxrwxrwx. 1 root root 13 Nov 20 12:44 scala -> scala-2.12.4

    符号链接的文件属性相同,真正的权限属性由符号链接所指向的实际文件决定.

  6. Linux关闭You have new mail in /var/spool/mail/root提示

    终端远程登陆Linux后经常提示You have new mail in /var/spool/mail/root 这个提示是LINUX会定时查看LINUX各种状态做汇总,每经过一段时间会把汇总的信息 ...

  7. Starting sshd: /var/empty/sshd must be owned by root and not group or world-writable.

    Starting sshd: /var/empty/sshd must be owned by root and not group or world-writable.      [FAILED] ...

  8. 关于Linux上的SSH服务无法启动,提示“/var/empty/sshd must be owned by root and not group or world-writable”错误

    首先通过物理终端进入到linux上,手工检查ssh发现没运行# /etc/init.d/sshd statussshd is stopped 手动启动服务,发现报告权限错误.# /etc/init.d ...

  9. Linux出现You have new mail in /var/spool/mail/root提示,关闭邮件提示清理内容的解决方案

    Linux出现You have new mail in /var/spool/mail/root提示,关闭邮件提示的解决方案 有的时候敲一下回车,就出来You have new mail in /va ...

随机推荐

  1. 406 UDP协议是面向非连接的协议 Keep-Alive

    HTTP The Definitive Guide   Table 3-1. Common HTTP methods   Method Description Message body?   GET ...

  2. TCP/IP建立连接的时候ISN序号分配问题

    初始建立TCP连接的时候的系列号(ISN)是随机选择的,那么这个系列号为什么不采用一个固定的值呢?主要有两方面的原因 防止同一个连接的不同实例(different instantiations/inc ...

  3. http的响应码及含义

    1xx(临时响应) 100: 请求者应当继续提出请求. 101(切换协议) 请求者已要求服务器切换协议,服务器已确认并准备进行切换. 2xx(成功) 200:正确的请求返回正确的结果 201:表示资源 ...

  4. vue-router实现路由懒加载( 动态加载路由 )

    三种方式第一种:vue异步组件技术 ==== 异步加载,vue-router配置路由 , 使用vue的异步组件技术 , 可以实现按需加载 .但是,这种情况下一个组件生成一个js文件.第二种:路由懒加载 ...

  5. DDD领域驱动设计:仓储

    1 前置阅读 在阅读本文章之前,你可以先阅读: 什么是DDD DDD的实体.值对象.聚合根的基类和接口:设计与实现 2 什么是仓储? 仓储封装了基础设施来提供查询和持久化聚合操作. 它们集中提供常见的 ...

  6. 数据分析中常用的Excel函数

    数据分析中excel是一个常见且基础的数据分析工具,要想掌握好它,学会使用其中的常用函数是一个绕不过去的坎.从网上搜集的资料来说,基本上确定了数据分析中Excel的常用函数有以下这六类 数学函数:SU ...

  7. Spark JDBC系列--取数的四种方式

    Spark JDBC系列--取数的四种方式 一.单分区模式 二.指定Long型column字段的分区模式 三.高自由度的分区模式 四.自定义option参数模式 五.JDBC To Other Dat ...

  8. 编程排序的一个excel-据说玩的好的,年薪50万了。只是你没在对的地方

    是一个excel 下面是百度网盘分享地址; http://pan.baidu.com/s/1kTwqRfL    

  9. 设计模式(十二)——享元模式(Integer缓冲池源码分析)

    1 展示网站项目需求 小型的外包项目,给客户 A 做一个产品展示网站,客户 A 的朋友感觉效果不错,也希望做这样的产品展示网站,但是要求都有些不同: 1) 有客户要求以新闻的形式发布 2) 有客户人要 ...

  10. Chocolate Bunny CodeForces - 1407C 思维

    题意: 交互题 题目输入一个n,你需要输出一个满足要求的[1,n]的排列. 你可以最多询问2*n次来确定你要输出的排列·中每一个位置的值 每一次询问格式为"? a b" 它会回复你 ...