简体   繁体   English

如何制作带有条形颜色的范围滑块

[英]How to make a range slider with spefic bar color

I would like to write a range slider in javascript with spefic bar color that does not depend on the position of the selector. 我想用带有特殊条形颜色的javascript写一个范围滑块,它不依赖于选择器的位置。 How can I do it ? 我该怎么做 ?

My inspiration is the following website 我的灵感来自以下网站

Using jQuery: 使用jQuery:

http://jsfiddle.net/LP5XA/4/ http://jsfiddle.net/LP5XA/4/

HTML: HTML:

<div id="slider"></div>

CSS: CSS:

#slider
{
    background-color:red;
    background-position:left;
    background-repeat:no-repeat;
    background-size:10px;
}

Javascript: Javascript:

$(function() {
    $( "#slider" ).slider(
    {
        slide:function(event, ui){
            //This is what the original code for this example looks like.
            //It's for changing the white/red area when the slider moves.
            //var w = $(ui.handle).css("left");
            //$(this).css("background-size",w);

            //Notice how when you set the "w" value to a static value it
            //will keep the white/red space static as well?  So you can 
            //change the colored space with whatever logic you want to use.
            $(this).css("background-size",50);
        }   
    });
});

Do whatever you want to do involving changing the width and color of the background. 做任何涉及更改背景的宽度和颜色的操作。 It seems like the website with your example does it based off a calculation done on the threshold between renting and buying and when one becomes ideal over another. 您所举的示例网站似乎是根据对租购之间的门槛值以及一个人对另一个人变得理想时所进行的计算得出的。

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

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