【问题标题】:jQuery Knob hover animationjQuery 旋钮悬停动画
【发布时间】:2013-10-23 16:27:03
【问题描述】:

我想为悬停时填充的旋钮圆圈设置动画。我是 Knob 的新手,所以我不知道我的错误在哪里,或者我是否有正确的方向。现在它甚至没有显示一个圆圈:(

基本上我只想在一个图标周围有一个圆圈,该图标在悬停时会填满。也许我可以更轻松地做到这一点?

这是它的解决方案,加上一个小修复,我将在正确的值处开始和停止,因此您可以在不破坏动画的情况下中断动画

HTML:

<input type="text" value="0" id="circle" />

Javascript:

$(function() {
$('.circle').knob({
    min: '0',
    max: '100',
    readOnly: true,
    displayInput: false
});

$('.circle').parent().hover( function() {console.log("hover");
                $({ value: $('.circle').val() }).animate(
                    { value: 100 }, 
                    {   duration: 300,
                        easing: 'swing',
                        progress: function() {
                          $('.circle').val(Math.round(this.value)).trigger('change');
                        }
                     });
             }, function() {
                $({ value: $('.circle').val() }).animate(
                    { value: 0 }, 
                    {
                        duration: 300,
                        easing: 'swing',
                        progress: function() {
                            $('.circle').val(Math.round(this.value)).trigger('change');
                        }
                     });
                });
});

这里是JSFiddle

【问题讨论】:

    标签: javascript jquery jquery-knob


    【解决方案1】:

    您需要将悬停处理程序更改为#circle 的父级或将 displayInput 更改为 true

    $(function() {
    $('#circle').knob({
        min: '0',
        max: '100',
        readOnly: true,
        displayInput: false
    });
    //$('#circle').parent() is the new div that contains the input and the canvas
    $('#circle').parent().hover( function() {
                    $({ value: 0 }).animate(
                        { value: 100 }, 
                        {   duration: 1000,
                            easing: 'swing',
                            progress: function() {
                              $('#circle').val(Math.round(this.value)).trigger('change');
                            }
                         });
                 }, function() {
                    $({ value: 100 }).animate(
                        { value: 0 }, 
                        {
                            duration: 1000,
                            easing: 'swing',
                            progress: function() {
                                $('#circle').val(Math.round(this.value)).trigger('change');
                            }
                         });
                    });
    });//you need to close with ');'    
    

    您需要在 fiddle 中包含 kub.js,否则您会收到“404 Not Found”错误并包含 jquery,否则您会收到此错误“Uncaught ReferenceError: $ is not defined”
    http://jsfiddle.net/dWsuP/1/

    【讨论】:

    • 嗯,它就像我想要的那样工作,但有一点例外:当你把鼠标移出圆圈时(当你不等待动画完成时)圆圈未满时,它将开始运行从 100 下降,但我想我知道如何解决这个问题。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多