질문
$(function() {
$(".slider").rangeslider();
});
$.fn.rangeslider = function(options) {
var obj = this;
var defautValue = obj.attr("value");
obj.wrap("<span class='range-slider'></span>");
obj.after("<span class='slider-container'><span class='bar'><span></span></span><span class='bar-btn'><span>0</span></span></span>");
obj.attr("oninput", "updateSlider(this)");
updateSlider(this);
return obj;
};
function updateSlider(passObj) {
var obj = $(passObj);
var value = obj.val();
var min = obj.attr("min");
var max = obj.attr("max");
var range = Math.round(max - min);
var percentage = Math.round((value - min) * 100 / range);
var nextObj = obj.next();
nextObj.find("span.bar-btn").css("left", percentage + "%");
nextObj.find("span.bar > span").css("width", percentage + "%");
nextObj.find("span.bar-btn > span").text(percentage);
};
.range-slider {
margin: 30px 0 0;
display: inline-block;
width: 100%;
box-sizing: border-box;
position: relative;
}
.range-slider>input {
opacity: 0;
width: 100%;
position: relative;
z-index: 5;
-webkit-appearance: none;
}
.range-slider>input::-webkit-slider-thumb {
-webkit-appearance: none;
z-index: 100;
position: relative;
width: 50px;
height: 30px;
-webkit-border-radius: 10px;
}
.range-slider>span.slider-container {
// min-height: 110px;
display: inline-block;
position: absolute;
top: 0px;
left: -8px;
right: 46px;
z-index: 3;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
.range-slider>span.slider-container>span.bar {
background-color: #e5e5e5;
display: inline-block;
position: absolute;
z-index: 1;
top: 17px;
left: 0;
right: 0;
height: 3px;
overflow: hidden;
border-radius: 10px;
}
.range-slider>span.slider-container>span.bar>span {
background: #d7302d;
background: -webkit-gradient(left top, right bottom, color-stop(0, #d7302d), color-stop(100%, #e82573));
background: linear-gradient(135deg, #d7302d 0, #e82573 100%);
display: inline-block;
float: left;
height: 3px;
width: 0%;
}
.range-slider>span.slider-container>span.bar-btn {
position: absolute;
text-align: center;
top: 0;
color: #fff;
font: 600 16px "Roboto Condensed", sans-serif;
z-index: 1;
text-align: center;
width: 38px;
height: 38px;
line-height: 38px;
}
.range-slider>span.slider-container>span.bar-btn:after {
content: "";
background-color: #cc202e;
border-radius: 20px;
width: 38px;
height: 38px;
display: inline-block;
position: absolute;
left: 0;
top: 0;
z-index: -1;
-webkit-box-shadow: 0 0 0 4px #cc202e;
box-shadow: 0 0 0 4px rgba(204, 32, 46, 0.2)
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<h1>Please Select</h1>
<input class="slider" value="20" min="0" max="100" name="rangeslider" type="range" />
나는 지난 이틀 동안이 코드로 내 head를 두들겨왔다. 많은 사이트에서 이에 대한 답을 얻을 수 없습니다. 도움을 받기 위해 Google과 w3schools를 검색했지만 어쨌든 나를 도울 수 있다고 생각하지 않습니다.
그래서 여기 와서 질문을 올렸어요
누구든지이 문제를 해결할 수 있다면 정말 감사하겠습니다.
답변1
입력
을 사용할 수 있습니다. 및 가져올 변경
이벤트 모든 브라우저에서 일관된 사용자 경험 :
$(this).on("change input", function() {
updateSlider(this);
});
$(function() {
$(".slider").rangeslider();
});
$.fn.rangeslider = function(options) {
var obj = this;
var defautValue = obj.attr("value");
obj.wrap("<span class='range-slider'></span>");
obj.after("<span class='slider-container'><span class='bar'><span></span></span><span class='bar-btn'><span>0</span></span></span>");
$(this).on("change input", function() {
updateSlider(this)
});
return obj;
};
function updateSlider(passObj) {
var obj = $(passObj);
var value = obj.val();
var min = obj.attr("min");
var max = obj.attr("max");
var range = Math.round(max - min);
var percentage = Math.round((value - min) * 100 / range);
var nextObj = obj.next();
nextObj.find("span.bar-btn").css("left", percentage + "%");
nextObj.find("span.bar > span").css("width", percentage + "%");
nextObj.find("span.bar-btn > span").text(percentage);
};
.range-slider {
margin: 30px 0 0;
display: inline-block;
width: 100%;
box-sizing: border-box;
position: relative;
}
.range-slider>input {
opacity: 0;
width: 100%;
position: relative;
z-index: 5;
-webkit-appearance: none;
}
.range-slider>input::-webkit-slider-thumb {
-webkit-appearance: none;
z-index: 100;
position: relative;
width: 50px;
height: 30px;
-webkit-border-radius: 10px;
}
.range-slider>span.slider-container {
// min-height: 110px;
display: inline-block;
position: absolute;
top: 0px;
left: -8px;
right: 46px;
z-index: 3;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
.range-slider>span.slider-container>span.bar {
background-color: #e5e5e5;
display: inline-block;
position: absolute;
z-index: 1;
top: 17px;
left: 0;
right: 0;
height: 3px;
overflow: hidden;
border-radius: 10px;
}
.range-slider>span.slider-container>span.bar>span {
background: #d7302d;
background: -webkit-gradient(left top, right bottom, color-stop(0, #d7302d), color-stop(100%, #e82573));
background: linear-gradient(135deg, #d7302d 0, #e82573 100%);
display: inline-block;
float: left;
height: 3px;
width: 0%;
}
.range-slider>span.slider-container>span.bar-btn {
position: absolute;
text-align: center;
top: 0;
color: #fff;
font: 600 16px "Roboto Condensed", sans-serif;
z-index: 1;
text-align: center;
width: 38px;
height: 38px;
line-height: 38px;
}
.range-slider>span.slider-container>span.bar-btn:after {
content: "";
background-color: #cc202e;
border-radius: 20px;
width: 38px;
height: 38px;
display: inline-block;
position: absolute;
left: 0;
top: 0;
z-index: -1;
-webkit-box-shadow: 0 0 0 4px #cc202e;
box-shadow: 0 0 0 4px rgba(204, 32, 46, 0.2)
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<h1>Please Select</h1>
<input class="slider" value="20" min="0" max="100" name="rangeslider" type="range" />
답변2
이 코드를 이전 코드로 바꾸십시오.
$(function() {
$(".slider").rangeslider();
});
$.fn.rangeslider = function(options) {
var obj = this;
var defautValue = obj.attr("value");
obj.wrap("<span class='range-slider'></span>");
obj.after("<span class='slider-container'><span class='bar'><span></span></span><span class='bar-btn'><span>0</span></span></span>");
$(obj).on("change", function() {
updateSlider(this)
});
return obj;
};
답변3
슬라이더 객체가 updateSlider ()
함수를 업데이트하고 트리거하려면 jquery onchange
를 사용해야하는 것 같습니다. IE 11에서는 약간 고르지 않지만 시작되었습니다. 업데이트하려면 IE에서 추가로 개선 할 수 있습니다. 아래 코드를 참조하십시오.
$(function() {
$(".slider").rangeslider();
});
$.fn.rangeslider = function(options) {
var obj = this;
var defautValue = obj.attr("value");
obj.wrap("<span class='range-slider'></span>");
obj.after("<span class='slider-container'><span class='bar'><span></span></span><span class='bar-btn'><span>0</span></span></span>");
$(obj).on("change", function() {
updateSlider(this)
});
return obj;
};
function updateSlider(passObj) {
var obj = $(passObj);
var value = obj.val();
var min = obj.attr("min");
var max = obj.attr("max");
var range = Math.round(max - min);
var percentage = Math.round((value - min) * 100 / range);
var nextObj = obj.next();
nextObj.find("span.bar-btn").css("left", percentage + "%");
nextObj.find("span.bar > span").css("width", percentage + "%");
nextObj.find("span.bar-btn > span").text(percentage);
};
.range-slider {
margin: 30px 0 0;
display: inline-block;
width: 100%;
box-sizing: border-box;
position: relative;
}
.range-slider>input {
opacity: 0;
width: 100%;
position: relative;
z-index: 5;
-webkit-appearance: none;
}
.range-slider>input::-webkit-slider-thumb {
-webkit-appearance: none;
z-index: 100;
position: relative;
width: 50px;
height: 30px;
-webkit-border-radius: 10px;
}
.range-slider>span.slider-container {
// min-height: 110px;
display: inline-block;
position: absolute;
top: 0px;
left: -8px;
right: 46px;
z-index: 3;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
.range-slider>span.slider-container>span.bar {
background-color: #e5e5e5;
display: inline-block;
position: absolute;
z-index: 1;
top: 17px;
left: 0;
right: 0;
height: 3px;
overflow: hidden;
border-radius: 10px;
}
.range-slider>span.slider-container>span.bar>span {
background: #d7302d;
background: -webkit-gradient(left top, right bottom, color-stop(0, #d7302d), color-stop(100%, #e82573));
background: linear-gradient(135deg, #d7302d 0, #e82573 100%);
display: inline-block;
float: left;
height: 3px;
width: 0%;
}
.range-slider>span.slider-container>span.bar-btn {
position: absolute;
text-align: center;
top: 0;
color: #fff;
font: 600 16px "Roboto Condensed", sans-serif;
z-index: 1;
text-align: center;
width: 38px;
height: 38px;
line-height: 38px;
}
.range-slider>span.slider-container>span.bar-btn:after {
content: "";
background-color: #cc202e;
border-radius: 20px;
width: 38px;
height: 38px;
display: inline-block;
position: absolute;
left: 0;
top: 0;
z-index: -1;
-webkit-box-shadow: 0 0 0 4px #cc202e;
box-shadow: 0 0 0 4px rgba(204, 32, 46, 0.2)
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<h1>Please Select</h1>
<input class="slider" value="20" min="0" max="100" name="rangeslider" type="range" />
출처 : https://stackoverflow.com/questions/47607004/range-slider-not-working-on-internet-explore-except-working-on-other-browsers