简体   繁体   English

与Jquery Ui滑块相乘

[英]Multiplication with Jquery Ui Slider

I am trying to build a ui slider similar to the one on this site: http://www.solarcity.com/ 我正在尝试构建类似于此网站上的ui滑块: http : //www.solarcity.com/

I want to be able to show the monthly value and then a yearly value next to it. 我希望能够在其旁边显示每月值,然后显示每年值。 ( I would assume multiplying the value of the monthly by 12 of course) (我当然假设将每月的值乘以12)

Once upon a time I had my slider working properly until I tried to multiply the monthly value by 12. 曾几何时,我一直在使滑块正常工作,直到尝试将月值乘以12。

What did I do wrong? 我做错了什么? (Sorry I am totally new to JavaScript) (对不起,我对JavaScript完全陌生)

Here is my Jsfiddle: http://jsfiddle.net/7qDyq/1/ 这是我的Jsfiddle: http : //jsfiddle.net/7qDyq/1/

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6/jquery.min.js"></script>

<span class="slider-output" id="monthly_bill">0</span>/month or <span class="slider-output" id="yearly_bill">0</span>/year

        <div id="bill_slider">

        </div>

$(document).ready(function(){

        function update() {
            var bill_slider = $('#bill_slider').slider('value');
            var yearly_bill = (monthly_bill * 12 ) 


            $("#monthly_bill").text(tasks_time);
            $("#monthly_bill").text(tasks_done);


        }

        $("#bill_slider").slider({
            value: 1,
            min: 0,
            max: 450,
            step: 5,
            slide: function() {
                update();
            }
        });


    });

Eventually after I figure this out I am also wondering how to change the color of the slider and words after the slider hits a certain point. 最终,我弄清楚了这一点之后,我还想知道如何在滑块达到特定点后更改滑块和单词的颜色。 (If then statement?) Not sure how to implement... (如果然后声明?)不确定如何执行...

Any help on this is greatly appreciated. 在此方面的任何帮助将不胜感激。 Thanks! 谢谢!

Most of the issues in your original jsFiddle traced back to bad JS var names; 您最初的jsFiddle中的大多数问题都可以追溯到错误的JS变量名称。 here is how you would achieve the desired effect: 这是达到预期效果的方法:

function update() {
        var bill_slider = $('#bill_slider').slider('value');
        var yearly_bill = (bill_slider * 12)
        $("#monthly_bill").text(bill_slider);
        $("#yearly_bill").text(yearly_bill);
    }

    $("#bill_slider").slider({
        value: 1,
        min: 0,
        max: 450,
        step: 5,
        slide: function () {
            update();
        }
    });

Working jsFiddle, forked from yours: http://jsfiddle.net/6Bprf/5/ 工作的jsFiddle,由您提供: http//jsfiddle.net/6Bprf/5/

If you update your question with a description & example of the color-coding you want to do, we can include that in our answers. 如果您用想要的颜色代码的描述和示例更新问题,我们可以将其包含在答案中。

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

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