YUI API 双滑块控制问题

发布于 2024-09-29 15:19:24 字数 1557 浏览 2 评论 0原文

我正在使用 YUI 2.7 库来处理网页中的双滑块(范围滑块)控件。

它效果很好——但是,我希望允许用户通过 Ajax 切换范围值——有效地将价格范围从“0-50,000”更改为子集(例如“50-250”),而无需重新加载页面。

问题是,即使我在函数内明确将它们设置回 NULL 以“重建”滑块,现有滑块中的值似乎也不会重置。

在 ajax 请求之后,滑块手柄出现错位(远离右侧的刻度),并且滑块的值显然是随机波动的。

除了将其引用设置为 null 之外,是否有办法显式销毁 YUI 滑块对象?或者我只需要以某种方式重新声明比例和最小/最大值?

感谢您的任何帮助(我将尝试尽快发布示例链接),

这是代码:

function slider(bg,minthumb,maxthumb,minvalue,maxvalue,startmin,startmax,aSliderName,soptions) {
        var scaleFactor = null;
        var tickSize = null;
        var range = null;
        var dual_slider = null;
        var initVals = null;
        var Dom = null;

        range = options.sliderLength;
        if ((startmax - startmin) < soptions.sliderLength) {
            tickSize = (soptions.sliderLength / (startmax - startmin));
        }else{
            tickSize = 1;
        }

        initVals = [ 0,soptions.sliderLength ], // Values assigned during instantiation
        //Event = YAHOO.util.Event,
        dual_slider,
        scaleFactor = ((startmax - startmin) / soptions.sliderLength); 

        dual_slider = YAHOO.widget.Slider.getHorizDualSlider(
        bg,minthumb,maxthumb,range, tickSize, initVals);

        dual_slider.subscribe("change", function(instance) {
            priceMin = (dual_slider.minVal * scaleFactor) + startmin;
            priceMax = (dual_slider.maxVal * scaleFactor) + startmin;
        });

        dual_slider.subscribe("slideEnd", function(){ alert(priceMin + ' ' + priceMax); });
        return dual_slider;
    }

I'm using the YUI 2.7 library to handle a dual-slider (range slider) control in a webpage.

It works great-- however, I wanted to allow users to switch the range values by Ajax-- effectively changing the price range from "0-50,000" to a subset (eg. "50-250") without reloading the page.

The problem is that it appears the values from the existing slider do not get reset, even when I explicitly set them back to NULL inside the function to "rebuild" the slider.

The slider handles appear out of position after the ajax request, (way off the scale to the right) and the values of the slider apparently randomly fluctuate.

Is there a way to explicitly destroy the YUI slider object, beyond setting its reference to null? Or do I just need to redeclare the scale and min/max values somehow?

Thanks for any help (I'll try to post a link to an example asap)

here's the code:

function slider(bg,minthumb,maxthumb,minvalue,maxvalue,startmin,startmax,aSliderName,soptions) {
        var scaleFactor = null;
        var tickSize = null;
        var range = null;
        var dual_slider = null;
        var initVals = null;
        var Dom = null;

        range = options.sliderLength;
        if ((startmax - startmin) < soptions.sliderLength) {
            tickSize = (soptions.sliderLength / (startmax - startmin));
        }else{
            tickSize = 1;
        }

        initVals = [ 0,soptions.sliderLength ], // Values assigned during instantiation
        //Event = YAHOO.util.Event,
        dual_slider,
        scaleFactor = ((startmax - startmin) / soptions.sliderLength); 

        dual_slider = YAHOO.widget.Slider.getHorizDualSlider(
        bg,minthumb,maxthumb,range, tickSize, initVals);

        dual_slider.subscribe("change", function(instance) {
            priceMin = (dual_slider.minVal * scaleFactor) + startmin;
            priceMax = (dual_slider.maxVal * scaleFactor) + startmin;
        });

        dual_slider.subscribe("slideEnd", function(){ alert(priceMin + ' ' + priceMax); });
        return dual_slider;
    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

调妓 2024-10-06 15:19:24

将startmin、startmax 和scaleFactor 存储在dual_slider 对象上,然后在ajax 回调中使用新值更新这些属性。更改您的更改事件订阅者以引用 this.startmin、this.startmax 和 this.scaleFactor。

Slider 和 DualSlider 仅真正了解拇指的像素偏移,并按此报告值。正如您所做的那样(以及大多数滑块示例),您需要应用转换因子将像素偏移转换为“值”。这种常见的习惯用法已被纳入 YUI 3 Slider 的核心逻辑中(尽管库中还没有 DualSlider)。

下面是一个说明动态更新值范围的示例:
http://yuiblog.com/sandbox/yui/v282/examples/slider /slider_factor_change.html

Store the startmin, startmax, and scaleFactor on the dual_slider object, then in your ajax callback, update those properties with new values. Change your change event subscriber to reference this.startmin, this.startmax, and this.scaleFactor.

Slider and DualSlider only really understand the pixel offsets of the thumbs, and report the values as such. As you've done (and per most Slider examples), you need to apply a conversion factor to translate a pixel offset to a "value". This common idiom has been rolled into the core logic of the YUI 3 Slider (though there isn't yet a DualSlider in the library).

Here's an example that illustrates dynamically updating value ranges:
http://yuiblog.com/sandbox/yui/v282/examples/slider/slider_factor_change.html

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文