jQuery 基础教程(第3版) ---第四章习题答案

    //第一题
    $('#container').fadeIn('slow');
    
    //第二题
    var color;
    $('p').hover(function(){
        color = $(this).css('backgroundColor');
        $(this).css('backgroundColor','yellow');
    },function(){
        $(this).css('backgroundColor',color);
    });
    
    //第三题
     $('div#container h2').click(function(){
        $(this).fadeTo('slow',0.25);
        $(this).css({'margin-left':'20px'});
    });  
    //或者
        $('div#container h2').click(function(){
        $(this).animate({
            opacity:0.25,
            'margin-left':'20px'
        },'slow');
    });
    
    
    //第四题
    $(document).keyup(function(event){
        $('#switcher').css('position','relative');
        switch(event.keyCode){
            case 37:
                $('#switcher').animate({'left':'-=20px'},'slow');
                break;
            case 38:
                $('#switcher').animate({'top':'-=20px'},'slow');
                break;
            case 39:
                $('#switcher').animate({'left':'+=20px'},'slow');
                break;
            case 40:
                $('#switcher').animate({'top':'+=20px'},'slow');
                break;
        }
    });

 

posted @ 2013-11-30 10:52  我只是程序员  阅读(369)  评论(0编辑  收藏  举报