简体   繁体   English

Hover 对属性的影响

[英]Hover Effect Over an Attribute

I am trying to figure out how to make a 10px halo over the -slider-thumb attribute of my range input slider. I am using React, CSS and HTML and have found this difficult to do because of the overflow:hidden property.我想弄清楚如何在我的范围输入 slider 的-slider-thumb属性上制作一个 10px 的光晕。我正在使用 React,CSS 和 HTML,并且发现由于overflow:hidden属性而很难做到这一点。 This property must stay, as basically none of the code works without it(This was part of a solution to editing the slider base css).这个属性必须保留,因为没有它基本上没有代码工作(这是编辑 slider 基本 css 的解决方案的一部分)。 I have tried using::after and::before with no avail.我试过使用 ::after 和 ::before 无济于事。 So I'm wondering what I'm doing wrong, or if this is even possible as I haven't found any documentation on it.所以我想知道我做错了什么,或者这是否可能,因为我还没有找到任何文档。 Code and Codepen provided below.下面提供了代码和 Codepen。 Thanks for any help/advice!感谢您的帮助/建议!

HTML: HTML:

<div id="root"></div>

CSS: CSS:

input[type='range'] {
  -webkit-appearance: none;
  background-color: #ddd;
  height: 10px;
  overflow: hidden;
  width: 300px;
  border-radius: 5px;
  outline: none;
}

input[type='range']::-webkit-slider-runnable-track {
  -webkit-appearance: none;
  height: 10px;
}

input[type='range']::-webkit-slider-thumb {
  -webkit-appearance: none;
  --slider-thumb-background-color: #000;
  background: var(--slider-thumb-background-color);
  border-radius: 50%;
  --box-shadow-color: orange;
  box-shadow: -205px 0 0 200px var(--box-shadow-color);
  cursor: pointer;
  height: 10px;
  width: 10px;
  --border-color: orange;
  border: 3px solid var(--border-color);
}

input[type='range']::-webkit-slider-thumb:hover::after {
  content: '';
  height: 10px;
  width: 10px;
  border-radius: 5px;
  color: yellow;
}

input[type='range']::-webkit-slider-thumb:hover {
  --slider-thumb-background-color: grey;
  --box-shadow-color: red;
  --border-color: red;
}

input[type='range']::-webkit-slider-thumb:active {
  --slider-thumb-background-color: white;
  --box-shadow-color: blue;
  --border-color: blue;
}

input[type='range']::-webkit-slider-thumb:focus {
  --slider-thumb-background-color: white;
  --box-shadow-color: yellow;
  --border-color: yellow;
}

input[type='range']::-webkit-slider-thumb:hover:after {
  border: 10px solid rgb(111, 111, 0.4);
  overflow: auto;
  postion: fixed;
}

input[type='range']::-moz-range-thumb {
  background: #333;
  border-radius: 50%;
  box-shadow: -1005px 0 0 1000px red;
  cursor: pointer;
  height: 10px;
  width: 10px;
  border: 0;
}

JS(Babel) JS(通天塔)

class VolumeSlider extends React.Component {
  
  constructor() {
    super();
    this.state = {
      value: 120.5
    };
  }

  onUpdate(e) {
    this.setState({
      value: e.target.value
    });
  }  

  render() {
    return (
      <div>
      
      <div className="mb1">
        <input
          className="c-input--range"
          list="tickmarks"
          max={1200}
          onChange={(e) => this.onUpdate(e)}
          step={0.1}
          type="range"
          value={this.state.value}
        />
        <div>
           <label className="c-label">{this.state.value}c</label>
        </div>
      </div>
      </div>
    );
  }
}

ReactDOM.render(
  <div>
    <VolumeSlider />
  </div>,
  document.getElementById("root")
);

https://codepen.io/kcandle/pen/KKMrZKo https://codepen.io/kcandle/pen/KKMrZKo

Look at this pen hope this is what you're looking for, explanation: i've added the after with position absolute made the input relative position made the after 1px X 1px, made inset then translated X axis from 0 to whatever value i want.看看这支笔希望这就是你要找的东西,解释:我已经添加了 position 绝对输入后使输入相对 position 使后 1px X 1px,插入然后将 X 轴从 0 转换为我想要的任何值.

    input[type='range']::after{
    content: "";
  position: absolute;
  top: 0px;
  left: 0px;
  border-radius: 50%;
  visibility: hidden;
   width: 1px;
    height: 1px;
  box-shadow: 0 0 10px 5px #fff, inset 0 0 10px 5px #fff;
}
input[type='range']:hover::after{
    visibility: visible;
  animation: wave 2s forwards;
}@keyframes wave {
  0% {
   
    transform:translateX(0);
  }
  100% {
    transform:translateX(500px);
  }
}

https://codepen.io/headsick/pen/xxOMXqw https://codepen.io/headsick/pen/xxOMXqw

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM