如何将此JS代码转换为Typescript?

时间:2019-09-09 18:31:13

标签: typescript

我想在我的component.ts文件中写入特殊的输入范围函数,但是我对此还是个初学者。你能帮我吗?

JS:

document.getElementById("myinput").oninput = function() {
  this.style.background = 'linear-gradient(to right, #82CFD0 0%, #82CFD0 '+this.value +'%, #fff ' + this.value + '%, white 100%)'
};

CSS:

#myinput {
  background: linear-gradient(to right, #82CFD0 0%, #82CFD0 50%, #fff 50%, #fff 100%);
  border: solid 1px #82CFD0;
  border-radius: 8px;
  height: 7px;
  width: 356px;
  outline: none;
  transition: background 450ms ease-in;
  -webkit-appearance: none;
}

HTML:

<div class="chrome">
  <input id="myinput" type="range" value="50" />
</div>

我发现了this.style.background错误,应该是(<HTMLElement>document.getElementById("myinput")).style 但我无法解决this.value问题。

完整代码如下:https://codepen.io/saintwycliffe/pen/VBGYXN

0 个答案:

没有答案