【问题标题】:Where is the bug in this jQuery code?这个 jQuery 代码中的错误在哪里?
【发布时间】:2011-09-24 02:20:28
【问题描述】:

我有这段代码,而 /**/ 中的部分有一些错误......我找不到它......当我删除这部分代码时它工作正常。

Problem

Solution

$(window).load(function(){
$('#cTop').toggle(
    function(){
        showC();
    },  
    function() {
        hideC();
    }
);

$('#textDownRight').click(function(){
    window.location = 'http://nitidus-consto.kilu.org';
    hideC();
});

    /* The buggy code starts here */
$('.menuCircle').hover(
    function () {
        $(this).animate({
            width: 55%,
            height: 55%
        }, 250);
    },
    function() {
        $(this).animate({
            width: 50%,
            height: 50%
        }, 250);
    });
    /*it ends here*/
});

function hideC(){
$('#c').animate({
    width: 100,
    height: 100,
    'margin-left': '-50px',
    'margin-top': '-50px'
    },500);
$('#cTop').animate({
    'backgroundColor': 'rgb(25,25,25)'
    }, 500);}

function showC(){
$('#c').animate({
    width: 200,
    height: 200,
    'margin-left': '-100px',
    'margin-top': '-100px'
    },500);
$('#cTop').animate({
    'backgroundColor': 'rgb(50,50,50)'
    }, 500);}

【问题讨论】:

    标签: javascript jquery html css hover


    【解决方案1】:

    试试这个

    http://jsfiddle.net/qHeMD/1/

    您在百分比值周围缺少引号

        $(this).animate({
            width: 55% ,
            height: 55%
        }, 250);
    }, function() {
        $(this).animate({
            width: 50%,
            height: 50%
        }, 250);
    

    应该是

        $(this).animate({
            width: '55 %' ,
            height: '55 %'
        }, 250);
    }, function() {
        $(this).animate({
            width: '50 %',
            height: '50 %'
        }, 250);
    

    【讨论】:

    • 它有效,但它没有动画..我想我会坚持使用 CSS :hover 功能...如果你能解决这个问题,就说吧:)..我不能9 分钟后接受,所以请稍等 :)
    • 当你删除数字和%之间的空格时它确实会动画,但这有点奇怪......jsfiddle.net/qHeMD
    • @DavidDebnar:是的,我知道当 % 和数字之间没有空格时它会这样做,但我认为这是不同的东西。现在将编辑我的答案
    • OP 还必须修改饼图的位置以使其看起来正确。
    • @BNL 所以我必须为每个切片创建不同的函数?那是我不想做的:(...
    【解决方案2】:

    尝试制作百分比字符串,如下所示:

    /* The buggy code starts here */
    $('.menuCircle').hover(
        function () {
        $(this).animate({
            width: '55%',
            height: '55%'
        }, 250);
    },
    function() {
        $(this).animate({
            width: '50%',
            height: '50%'
        }, 250);
    });
    /*it ends here*/
    });
    

    【讨论】:

      猜你喜欢
      • 2011-05-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-10-12
      • 1970-01-01
      • 2015-07-13
      • 1970-01-01
      相关资源
      最近更新 更多