javascript - 将 mootools 代码转换为 jquery

标签 javascript jquery mootools

我有一个 slider ,我正在操纵它的颜色和渐变。

它使用 mootools,一切正常。

JSFIDDLE

var inputs = document.getElementsByTagName('input');
inputs = Array.splice(inputs, 0);
inputs.forEach(function (item) {
    if (item.type === 'range') {
        item.onchange = function () {
            value = (item.value - item.min)/(item.max - item.min)
            item.style.backgroundImage = [
                '-webkit-gradient(',
                  'linear, ',
                  'left top, ',
                  'right top, ',
                  'color-stop(' + value + ', #0B8CDD), ',
                  'color-stop(' + value + ', #898989)',
                ')'
            ].join('');
        };
    }
});

我想将 Mootools js 代码转换为 Js/Jquery。

请帮帮我。

最佳答案

尝试

使用elementattribute selectors要定位 input type="range" 元素,请使用 change()方法注册更改事件处理程序然后使用 .css()设置CSS属性

$('input[type="range"]').change(function () {
    //`this` inside the handler refers to the current input element
    var value = (this.value - this.min) / (this.max - this.min);
    //use `.css()` to set the css properties
    $(this).css('backgroundImage', [
        '-webkit-gradient(',
        'linear, ',
        'left top, ',
        'right top, ',
        'color-stop(' + value + ', #0B8CDD), ',
        'color-stop(' + value + ', #898989)',
        ')'].join(''));
});

演示:Fiddle

关于javascript - 将 mootools 代码转换为 jquery,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20355331/

相关文章:

javascript - AngularJS 路由 : Keep view loaded, 但不可见(保存滚动位置并防止重新加载数据)

javascript - 使用框输入重定向页面

javascript - Mootools 构建表单

javascript - MooTools Class.extend 有困难

javascript - console.log 变量时 target.dispatchEvent 上的 TypeError

javascript - 从 server.js 中删除 browsersync 以进行 gulp

javascript - 如何实现 twitter bootstrap Accordion ?

php - 从表中获取数据到 php

javascript - 如何将类别屏幕添加到我正在制作的应用程序中?

javascript - 普通 JavaScript 是否比使用 jQuery 或 MooTools 等框架更好?