首页 > Web开发 > 详细

js操作css变量

时间:2018-01-24 19:21:01      阅读:205      评论:0      收藏:0      [点我收藏+]

原文:
http://css-live.ru/articles/dostup-k-css-peremennym-i-ix-izmenenie-spomoshhyu-javascript.html

  :root {
    --footer-color: #2cba92;
    /* @reasonCode зеленый */
    --palatte-padding-left: 0px
  }

  footer {
    width: 50px;
    height: 50px;
    margin-top: 20px;
    margin-left: var(--palatte-padding-left);
    background-color: var(--footer-color);
    border-radius: 15px;
  }
  const footer = document.querySelector(‘footer‘)
  const inputs = [].slice.call(document.querySelectorAll(‘input‘));

  inputs.forEach(input => input.addEventListener(‘change‘, handleUpdate));
  inputs.forEach(input => input.addEventListener(‘mousemove‘, handleUpdate));

  function handleUpdate(e) {
    if (this.type === ‘color‘) {
      footer.style.setProperty(‘--footer-color‘, this.value)
    } else {
      footer.style.setProperty(‘--palatte-padding-left‘, this.value + ‘px‘)
    }
  }
  <body style="padding: 20px">
    <label>Выберите свой любимый цвет:</label>
    <input type="color" value="#2cba92">
    <br/>
    <label>Настройте отступ:</label>
    <input type="range" id="margin" min="10" max="200" value="0">
    <footer></footer>
  </body>
?

js操作css变量

原文:https://www.cnblogs.com/daysme/p/8342898.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!