简体   繁体   English

Range Slider无法在Internet Explorer上运行,只能在其他浏览器上运行

[英]Range Slider not working on internet explore except working on other browsers

My range slider is not working on internet explore 11 except all the other browser is support this plugin 100% and also working fine. 我的范围滑块在Internet Explorer 11上不起作用,除了所有其他浏览器均100%支持该插件并且也可以正常工作。

 $(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" /> 

I have been banging my head with this code from last two days. 最近两天来,我一直在用这段代码来敲打我的头。 I cannot get any answer for this from many sites. 我无法从许多站点得到任何答案。 I have searched google and w3schools to get help but I don't think so that they can help me anyways. 我已经搜索过Google和w3schools以获得帮助,但我认为这样他们无论如何都可以帮助我。

So, I came here and posting the question 所以,我来到这里发布问题

If anyone can solve this issue that would be really appreciated. 如果有人可以解决这个问题,将不胜感激。

You can use the input and change events to get a consistent user experience in all browsers: 您可以使用inputchange事件在所有浏览器中获得一致的用户体验:

 $(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" /> 

Just replace this code with the old one 只需用旧代码替换此代码

$(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;
};

Well looks like you need to use the jquery onchange for the slider object to update and trigger the updateSlider() function, tho it is a bit choppy in IE 11 but it started to update it, in IE, you can further make improvements, see code below 看起来您需要为滑块对象使用jquery onchange来更新和触发updateSlider()函数,这在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" /> 

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

相关问题 createRange函数在IE以外的其他浏览器中不起作用 - createRange function is not working in other browsers except IE jQuery无法在Internet Explorer中像在其他浏览器中一样工作 - jQuery not working in Internet Explorer as it does in other browsers 与数学相关的 Javascript 适用于除 Internet Explorer 之外的所有浏览器 - Math-related Javascript working in all browsers except Internet Explorer 为什么JavaScript样式可用于Internet Explorer以外的所有浏览器? - Why is JavaScript styling working with all browsers except Internet Explorer? navigator.sendBeacon 在 Internet Explorer 浏览器中不起作用 - navigator.sendBeacon not working in internet explore browser jquery animate scrollTop函数无法在Internet Explorer中运行 - jquery animate scrollTop function is not working in internet explore 输入类型日期,时间在Chrome浏览器以外的其他浏览器上不起作用 - Input type date ,time not working on other browsers except Chrome window.getComputedStyle不适用于除Chrome之外的其他浏览器的速记属性 - window.getComputedStyle not working for shorthand properties in other browsers except Chrome 输入范围滑块的Javascript代码在Internet Explorer 11中不起作用 - Javascript code for Input range slider not working in internet explorer 11 .keypress在浏览器中不起作用(Chrome浏览器除外) - .keypress not working in browsers (except chrome)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM