可以使用单个输入滑块来更改多个数值吗?

huangapple go评论96阅读模式
英文:

Is it possible to change multiple values with the help of a single input slider?

问题

以下是您提供的内容的中文翻译:

"Is it possible to change multiple values with a single input slider? Because I tried many times but was unable to change different values. I want to change the value of 50,000 which is at the top of the slider, and the value of 250k which is in the unique view's container. When we move the slider forward the 50,000 value should be changed to 10,000 per step i.e. 50,000 then 60,000 then 70,000 and so on till 1,000,000. And the value of 250k should be changed to 50K per step i.e. 250k then 300k then 350k and so on till 5M. I have made this in HTML, CSS, and JavaScript. Codes are as follows-"

"是否可以通过单个输入滑块更改多个值?因为我尝试了很多次,但无法更改不同的值。我想要更改位于滑块顶部的50,000的值,以及位于独特视图容器中的250k的值。当我们向前移动滑块时,50,000的值应该每步更改为10,000,即50,000,然后60,000,然后70,000等,直到1,000,000。而250k的值应该每步更改为50K,即250k,然后300k,然后350k等,直到5M。我使用HTML、CSS和JavaScript制作了这个。代码如下:"

(以下是代码部分,没有翻译)

英文:

Is it possible to change multiple values with a single input slider? Because I tried many times but was unable to change different values. I want to change the value of 50,000 which is at the top of the slider, and the value of 250k which is in the unique view's container. When we move the slider forward the 50,000 value should be changed to 10,000 per step i.e. 50,000 then 60,000 then 70,000 and so on till 1,000,000. And the value of 250k should be changed to 50K per step i.e. 250k then 300k then 350k and so on till 5M. I have made this in HTML, CSS, and JavaScript. Codes are as follows-

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-js -->

const input = document.querySelector(&quot;input&quot;),
        number = document.querySelector(&quot;.slide-value&quot;),
        uniqueViews = document.querySelector(&quot;.unique_views&quot;);

    input.addEventListener(&quot;input&quot;, () =&gt; {
        number.textContent = input.value.replace(/\B(?=(\d{3})+(?!\d))/g, &quot;,&quot;);
    });

<!-- language: lang-css -->

.campaign {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
    }

    .campaign .campaign-details {
        display: flex;
        align-items: center;
        flex-direction: column;
        width: 75%;
        background: gray;
        box-shadow: 5px 5px 4px rgba(0, 0, 0, .16);
        border-radius: 10px;
        margin-top: 60px;
        padding: 20px 0;
    }

    .campaign .campaign-details .campaign-container .campaign-cards {
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 32px;
        margin: 0 10%;
    }

    .campaign .campaign-details .campaign-container .campaign-cards .card {
        width: calc(25% - 30px);
        border: 1px solid red;
        height: 50px;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: flex-start;
        padding: 35px 30px;
    }

    .campaign .campaign-details .campaign-container .campaign-slider {
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .campaign .campaign-details .campaign-container .campaign-slider .wrapper {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        height: 130px;
        width: 100%;
        border: 1px solid red;
    }

    .campaign .campaign-details .campaign-container .campaign-slider .wrapper .slide-value {
        font-size: 27px;
        font-weight: 500;
        color: #333;
        width: 70px;
        text-align: center;
    }

    .campaign .campaign-details .campaign-container .campaign-slider .wrapper input {
        width: 100%;
        appearance: none;
        height: 12px;
        background-color: #bdd6f9;
    }

    .campaign .campaign-details .campaign-container .campaign-slider .wrapper input::-webkit-slider-thumb {
        appearance: none;
        height: 18px;
        width: 18px;
        border: 2px solid #fff;
        background-color: #fff;
        box-shadow: 0.5px 0.5px 4px -1.5px #000;
    }

    .campaign .campaign-details .campaign-container .campaign-slider .wrapper .min-max-value {
        width: 100%;
        display: flex;
        align-items: center;
        justify-content: space-between;
    }

    .campaign .campaign-details .campaign-container .campaign-matrics {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 20px;
    }

    .campaign .campaign-details .campaign-container .campaign-matrics .matrics-block {
        border: 1px solid red;
        background-color: #fff;
        border-radius: 4px;
        display: flex;
        align-items: center;
        justify-content: center;
        padding: 10px 60px;
        width: 50%;
        margin: 0 20px;
    }

<!-- language: lang-html -->

&lt;div class=&quot;campaign&quot;&gt;
        &lt;h2 class=&quot;header custom-cursor&quot;&gt;Making Influencer Campaign Simple&lt;/h2&gt;
        &lt;div class=&quot;details campaign-details&quot;&gt;
            &lt;div class=&quot;campaign-container&quot;&gt;
                &lt;div class=&quot;campaign-cards&quot;&gt;
                    &lt;div class=&quot;card&quot;&gt;
                        &lt;div class=&quot;title&quot;&gt;
                            &lt;h3&gt;Traffic&lt;/h3&gt;
                        &lt;/div&gt;
                    &lt;/div&gt;
                &lt;/div&gt;

                &lt;div class=&quot;campaign-slider&quot;&gt;
                    &lt;div class=&quot;wrapper&quot;&gt;
                        &lt;span class=&quot;slide-value&quot;&gt;50,000&lt;/span&gt;
                        &lt;input type=&quot;range&quot; min=&quot;50000&quot; step=&quot;10000&quot; max=&quot;1000000&quot; value=&quot;50000&quot; /&gt;
                        &lt;div class=&quot;min-max-value&quot;&gt;
                            &lt;p&gt;Min: ₹50,000&lt;/p&gt;
                            &lt;p&gt;Max: ₹1,000,000&lt;/p&gt;
                        &lt;/div&gt;
                    &lt;/div&gt;
                &lt;/div&gt;

                &lt;div class=&quot;campaign-matrics&quot;&gt;
                    &lt;div class=&quot;matrics-block&quot;&gt;
                        &lt;div class=&quot;matrics-title&quot;&gt;
                            &lt;h4&gt;Unique Views&lt;/h4&gt;
                        &lt;/div&gt;
                        &lt;div class=&quot;matrics-value&quot;&gt;
                            &lt;h2 class=&quot;unique_views&quot;&gt;250K&lt;/h2&gt;
                        &lt;/div&gt;
                    &lt;/div&gt;

                    &lt;div class=&quot;matrics-block&quot;&gt;
                        &lt;div class=&quot;matrics-title&quot;&gt;
                            &lt;h4&gt;Cost per View&lt;/h4&gt;
                        &lt;/div&gt;
                        &lt;div class=&quot;matrics-value&quot;&gt;
                            &lt;h2&gt;0.2&lt;/h2&gt;
                        &lt;/div&gt;
                    &lt;/div&gt;
                &lt;/div&gt;
            &lt;/div&gt;
        &lt;/div&gt;
    &lt;/div&gt;

<!-- end snippet -->

答案1

得分: 1

我建议您使用jQuery。

首先,我在您的“unique_views”值周围放置了一个,以便可以使用选择器更轻松地获取该值。

然后,我捕捉了滑块变化的事件,并获取“unique_views”的值,然后将新值乘以5。

const input = document.querySelector("input"),
        number = document.querySelector(".slide-value"),
        uniqueViews = document.querySelector(".unique_views");

    input.addEventListener("input", () => {
        number.textContent = input.value.replace(/\B(?=(\d{3})+(?!\d))/g, ",");
    });
    
$('input').on("input change",(e)=>{
  // 获取当前“unique_views”的值
  var unique_views = $('.unique_views').find('span').text(); 
  // 获取当前滑块的值并移除最后3位数字
  var current_slider_val = e.target.value.substring(0, e.target.value.length-3);
  // 计算新的“unique_views”值
  var new_unique_views = current_slider_val * 5;
  // 设置新的“unique_views”值
  $('.unique_views span').text(new_unique_views);
});

CSS部分:

/* CSS部分略 */

HTML部分:

<!-- HTML部分略 -->

请注意,这只是代码的一部分,如果需要完整的代码,请提供更多上下文或详细信息。

英文:

I purpose to you to use jQuery.

First i placed span arround the value of your "unique_views" to get the value easier with selector.

Then i catch the event of slider change and get the value for "unique_views" and set the new value multiply by 5.

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-js -->

const input = document.querySelector(&quot;input&quot;),
        number = document.querySelector(&quot;.slide-value&quot;),
        uniqueViews = document.querySelector(&quot;.unique_views&quot;);

    input.addEventListener(&quot;input&quot;, () =&gt; {
        number.textContent = input.value.replace(/\B(?=(\d{3})+(?!\d))/g, &quot;,&quot;);
    });
    
$(&#39;input&#39;).on(&quot;input change&quot;,(e)=&gt;{
  // get the current value of &quot;unique_views&quot;
  var unique_views = $(&#39;.unique_views&#39;).find(&#39;span&#39;).text(); 
  // get the value of current slider and remove 3 last digit
  var current_slider_val = e.target.value.substring(0, e.target.value.length-3);
  // apply calculation for the new value of &quot;unique_views&quot;
  var new_unique_views = current_slider_val * 5;
  // set the new value of &quot;unique_views&quot;
  $(&#39;.unique_views span&#39;).text(new_unique_views);
});

<!-- language: lang-css -->

.campaign {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
    }

    .campaign .campaign-details {
        display: flex;
        align-items: center;
        flex-direction: column;
        width: 75%;
        background: gray;
        box-shadow: 5px 5px 4px rgba(0, 0, 0, .16);
        border-radius: 10px;
        margin-top: 60px;
        padding: 20px 0;
    }

    .campaign .campaign-details .campaign-container .campaign-cards {
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 32px;
        margin: 0 10%;
    }

    .campaign .campaign-details .campaign-container .campaign-cards .card {
        width: calc(25% - 30px);
        border: 1px solid red;
        height: 50px;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: flex-start;
        padding: 35px 30px;
    }

    .campaign .campaign-details .campaign-container .campaign-slider {
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .campaign .campaign-details .campaign-container .campaign-slider .wrapper {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        height: 130px;
        width: 100%;
        border: 1px solid red;
    }

    .campaign .campaign-details .campaign-container .campaign-slider .wrapper .slide-value {
        font-size: 27px;
        font-weight: 500;
        color: #333;
        width: 70px;
        text-align: center;
    }

    .campaign .campaign-details .campaign-container .campaign-slider .wrapper input {
        width: 100%;
        appearance: none;
        height: 12px;
        background-color: #bdd6f9;
    }

    .campaign .campaign-details .campaign-container .campaign-slider .wrapper input::-webkit-slider-thumb {
        appearance: none;
        height: 18px;
        width: 18px;
        border: 2px solid #fff;
        background-color: #fff;
        box-shadow: 0.5px 0.5px 4px -1.5px #000;
    }

    .campaign .campaign-details .campaign-container .campaign-slider .wrapper .min-max-value {
        width: 100%;
        display: flex;
        align-items: center;
        justify-content: space-between;
    }

    .campaign .campaign-details .campaign-container .campaign-matrics {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 20px;
    }

    .campaign .campaign-details .campaign-container .campaign-matrics .matrics-block {
        border: 1px solid red;
        background-color: #fff;
        border-radius: 4px;
        display: flex;
        align-items: center;
        justify-content: center;
        padding: 10px 60px;
        width: 50%;
        margin: 0 20px;
    }

<!-- language: lang-html -->

&lt;script src=&quot;https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js&quot;&gt;&lt;/script&gt;
&lt;div class=&quot;campaign&quot;&gt;
        &lt;h2 class=&quot;header custom-cursor&quot;&gt;Making Influencer Campaign Simple&lt;/h2&gt;
        &lt;div class=&quot;details campaign-details&quot;&gt;
            &lt;div class=&quot;campaign-container&quot;&gt;
                &lt;div class=&quot;campaign-cards&quot;&gt;
                    &lt;div class=&quot;card&quot;&gt;
                        &lt;div class=&quot;title&quot;&gt;
                            &lt;h3&gt;Traffic&lt;/h3&gt;
                        &lt;/div&gt;
                    &lt;/div&gt;
                &lt;/div&gt;

                &lt;div class=&quot;campaign-slider&quot;&gt;
                    &lt;div class=&quot;wrapper&quot;&gt;
                        &lt;span class=&quot;slide-value&quot;&gt;50,000&lt;/span&gt;
                        &lt;input type=&quot;range&quot; min=&quot;50000&quot; step=&quot;10000&quot; max=&quot;1000000&quot; value=&quot;50000&quot; /&gt;
                        &lt;div class=&quot;min-max-value&quot;&gt;
                            &lt;p&gt;Min: ₹50,000&lt;/p&gt;
                            &lt;p&gt;Max: ₹1,000,000&lt;/p&gt;
                        &lt;/div&gt;
                    &lt;/div&gt;
                &lt;/div&gt;

                &lt;div class=&quot;campaign-matrics&quot;&gt;
                    &lt;div class=&quot;matrics-block&quot;&gt;
                        &lt;div class=&quot;matrics-title&quot;&gt;
                            &lt;h4&gt;Unique Views&lt;/h4&gt;
                        &lt;/div&gt;
                        &lt;div class=&quot;matrics-value&quot;&gt;
                            &lt;h2 class=&quot;unique_views&quot;&gt;&lt;span&gt;250&lt;/span&gt;K&lt;/h2&gt;
                        &lt;/div&gt;
                    &lt;/div&gt;

                    &lt;div class=&quot;matrics-block&quot;&gt;
                        &lt;div class=&quot;matrics-title&quot;&gt;
                            &lt;h4&gt;Cost per View&lt;/h4&gt;
                        &lt;/div&gt;
                        &lt;div class=&quot;matrics-value&quot;&gt;
                            &lt;h2&gt;0.2&lt;/h2&gt;
                        &lt;/div&gt;
                    &lt;/div&gt;
                &lt;/div&gt;
            &lt;/div&gt;
        &lt;/div&gt;
    &lt;/div&gt;

<!-- end snippet -->

huangapple
  • 本文由 发表于 2023年8月5日 13:51:58
  • 转载请务必保留本文链接:https://go.coder-hub.com/76840326.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定