简体   繁体   English

调整jQuery进度目标指标以包括待处理指标

[英]Adapt jQuery progress goal meter to include pending meter

I am trying to adapt the GoalMeter jQuery plugin to include a pending meter that can be displayed alongside the progress meter. 我正在尝试将GoalMeter jQuery插件改编为包括一个待处理仪表,该仪表可以与进度表一起显示。 I have created a CodePen and made some adaptations that can be viewed here: http://codepen.io/mikehermary/pen/xwEypo 我创建了一个CodePen,并做了一些修改,可以在这里查看: http ://codepen.io/mikehermary/pen/xwEypo

update: function goalMeter_update(options) {
        if (typeof options === "object") {
            this.extendOptions(options);
        }

        // Get ze values
        this.goalAmount = this.getGoalAmount();
        this.progressAmount = this.getProgressAmount();
        this.pendingAmount = this.getPendingAmount();

        // Apply some math to this stuff.
        this.progressPercentageAmount = Math.min(
            Math.round(
                this.progressAmount / this.goalAmount * 1000
            ) / 10, 100
        ); //make sure we have 1 decimal point :)

        // figure out the new width/height
        this.newCSS[ this.isHorizontal ? "width" : "height" ] = this.progressPercentageAmount + "%";

        // render stuff. Yeah.
        this.render();

        // Apply some math to this stuff.
        this.pendingPercentageAmount = Math.min(
            Math.round(
                this.pendingAmount / this.goalAmount * 1000
            ) / 10, 100
        ); //make sure we have 1 decimal point :)

        // figure out the new width/height
        this.newCSS[ this.isHorizontal ? "width" : "height" ] = this.pendingPercentageAmount + "%";

        // render stuff. Yeah.
        this.render();

    },

This is the function that controls the meters and their vertical heights. 这是控制仪表及其垂直高度的功能。 As you can see in the CodePen example, the pending meter is overriding the donated meter. 正如您在CodePen示例中看到的那样,挂起的计量表将覆盖捐赠的计量表。 How can I make each meter independent? 如何使每个仪表独立?

After some minor head scratching and trial and error, I have figured it out. 经过一些小小的头部抓挠和反复试验后,我已经弄清楚了。 The problem was solved by changing newCSS to progressCSS and pendingCSS for the horizontal or vertical display of the meter, then removing the first this.render function call. 通过将newCSS更改为progressCSS计量CSS的水平或垂直显示的未决CSS ,然后除去第一个this.render函数调用,解决了该问题。 After these changes, the meters work and animate independently of each other. 完成这些更改后,仪表将彼此独立地工作和设置动画。

I then figured out the z-indexes for each meter would need to switch, depending on which value was lower. 然后,我确定了需要切换的每米的z索引,具体取决于哪个值较低。 If the progress value was lower, then it would need a higher z-index than pending and vice versa. 如果进度值较低,则它需要的z索引比挂起的索引高,反之亦然。 I have attached the updated function from my previous example to show my changes. 我已经附加了上一个示例中的更新功能,以显示所做的更改。

update: function goalMeter_update(options) {
        if (typeof options === "object") {
            this.extendOptions(options);
        }

        // Get the values
        this.goalAmount = this.getGoalAmount();
        this.progressAmount = this.getProgressAmount();
        this.pendingAmount = this.getPendingAmount();

        // Apply some math to this stuff.
        this.progressPercentageAmount = Math.min(
            Math.round(
                this.progressAmount / this.goalAmount * 1000
            ) / 10, 100
        ); //make sure we have 1 decimal point :)

        // figure out the new width/height
        this.progressCSS[ this.isHorizontal ? "width" : "height" ] = this.progressPercentageAmount + "%";

        // Apply some math to this stuff.
        this.pendingPercentageAmount = Math.min(
            Math.round(
                this.pendingAmount / this.goalAmount * 1000
            ) / 10, 100
        ); //make sure we have 1 decimal point :)

        // figure out the new width/height
        this.pendingCSS[ this.isHorizontal ? "width" : "height" ] = this.pendingPercentageAmount + "%";

        // Set the z-index values
        if (this.progressAmount > this.pendingAmount) {
            this.progressCSS[ "z-index" ] = "1";
        }
        if (this.progressAmount < this.pendingAmount) {
            this.pendingCSS[ "z-index" ] = "1";
        }

        // render stuff. Yeah.
        this.render();

    },

I hope this may be helpful to anyone looking to achieve the same results with this plugin or jQuery in general. 我希望这可能对希望通过此插件或jQuery实现相同结果的任何人有所帮助。

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

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