2011-09-23 78 views
0

我有这段代码和/ ** /中的部分有一些错误...我找不到它......当我删除代码的那部分工作正常。这个jQuery代码中的错误在哪里?

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);} 

回答

6

试试这个

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); 
+1

它的工作原理,但它并没有设置动画..我想我就坚持在CSS:悬停功能...如果你能解决这个问题,只是说:)我不能接受它在9分钟内,所以只是等待:) –

+0

@DavidDebnar:现在看它;) – genesis

+0

它删除空间时会动画在数字和%之间,但它有点怪异... http://jsfiddle.net/qHeMD/ –

1

尝试使百分比字符串,像这样:

/* 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*/ 
});