【发布时间】:2019-12-27 10:46:56
【问题描述】:
我正在复制此网页https://www.modsy.com/project/furniture,但图像不会根据范围滑块而改变 我的html代码是:
<div class="image mt-3 mb-3">
<img src="../static/images/7.jpg" width="400" height="180">
<img src="../static/images/8.jpg" width="400" height="180">
<img src="../static/images/9.jpg" width="400" height="180">
</div>
<br>
<div class="rangeslider">
<input type="range" min="1" max="3" value="3" class="myslider" id="sliderRange">
<div class="row mt-3">
<div class="col-4">
<h6 class="display-6">Starting From Scratch</h6>
<p id="demo"> I'm designing the room </p>
</div>
<div class="col-4">
<h6 class="display-6">Somewhere in Between</h6>
<p class="demo">I'm designing around a few pieces I already own</p>
</div>
<div class="col-4">
<h6 class="display-6">Mostly Furnished</h6>
<p class="demo">I want to put the finishing touches on my room</p>
</div>
</div>
</div>
我的 JS 代码:
<script>
var rangeslider = document.getElementById("sliderRange");
var output = document.getElementById("demo");
output.innerHTML = rangeslider.value;
rangeslider.oninput = function() {
output.innerHTML = this.value;
}
</script>
我的 CSS 代码:
<style>
.rangeslider{
width: 50%;
}
.myslider {
-webkit-appearance: none;
background: #FCF3CF ;
width: 50%;
height: 20px;
opacity: 2;
}
.myslider::-webkit-slider-thumb {
-webkit-appearance: none;
cursor: pointer;
background: #34495E ;
width: 5%;
height: 20px;
}
.myslider:hover {
opacity: 1;
}
</style>
错误是:未捕获的类型错误:无法读取 null 的属性“值” 你能说我在代码中犯了什么错误
【问题讨论】:
-
尝试将脚本标签移动到 html 文档的底部
-
@Ryan 我收到错误,因为 Uncaught TypeError: Cannot set property 'innerHTML' of null 你能帮帮我吗
-
滑动范围滑块时图像也没有变化如何实现这一点
标签: javascript html