在jquery .css()和.animate()之后丢失样式

时间:2013-08-29 23:03:42

标签: jquery

在我的动画之后,我放松了这些CSS样式。有没有办法可以使用像。()追加的东西来添加它们?而不是$(this).removeAttr('style');

.grid li a:hover img {

-webkit-transition: opacity .3s ease-in;
-moz-transition: opactiy .3s ease-in;
-ms-transition: opacity .3s ease-in;
-o-transition: opacity .3s ease-in;
transition: opacity .3s ease-in;
opacity: 1;
}

.grid:hover li {   
 -webkit-transition: opacity .3s ease-in;
 -moz-transition: opactiy .3s ease-in;
 -ms-transition: opacity .3s ease-in;
 -o-transition: opacity .3s ease-in;
 transition: opacity .3s ease-in;   
 zoom: 1;
 filter: alpha(opacity=1);
 opacity: 0.3;
}

以下是正在制作动画的代码

  $('#container img').addClass("img_org");
    $(this).siblings().css("top", "0px");
     $(this).siblings().stop();
    $(this).parent().detach();       
    $('.pop_title').css({ "margin-left": "25%", "margin-right": "25%", top: "100px", left: "0", "font-size": "200%"});      
    $('#container').css({ left: image.left, top: image.top, opacity: 1})
                   .animate({marginLeft: '25%',marginRight: '25%', top: '150', left: '0'},200,'easeInCubic', function(){

       $('.nextButton, .prevButton, .zoom_back, .zoom_big, .info, .box_counter ').animate({opacity: 1},500);            
       $('.pop_title').css("font-size", "200%").text(content.navgrid[2][location].title);
            });           

    $('#container ul, #container').css({height: "422px",width: "679px"});

1 个答案:

答案 0 :(得分:0)

如果您正在谈论移除内联CSS的动画方法,则应选择其他方法。 尝试添加原始类:

.exampleClass
{
    height:50px;
}

创建该类的div:

<div class="exampleClass"></div>

动画:

$('.exampleClass').animate({height:'100px'}, 200);

删除内联样式以恢复原始CSS:

$('.exampleClass').removeAttr('style');

你会保留原来的CSS,因为它仍然是样式表。

DEMO