2013-04-01 64 views
3

我有下面的jQuery代码,我需要清除此动画所jQuery的清除内联CSS

$(document).ready(function(){ 

$("#panel").hide(); //updated line, removing the #panel ID. 

$('#tab2').toggle(function(){ //adding a toggle function to the #tab 
    $("#panel").show(); 

     $('#ToolsTitleSpan').text("CLOSE TOOLS"); 

     $('#tab2').stop().animate({right: '225'}, 800, 'swing', function() {}); 

     $("#panel").stop().animate({right: '72', width: '230px', opacity:0.8}, 800, 'swing', function() { 

       $('.contentSideBar').fadeIn('slow');   
    }); 


}, 

function(){ //when the #tab is next cliked 
$('#ToolsTitleSpan').text("OPEN TOOLS"); 

$('#tab2').stop().animate({right: '-=225'}, 800, 'swing', function() { 

      $('.contentSideBar').fadeOut(slow, function() {}); 
}); 

$('#panel').stop().animate({width:"0", position:'absolute', float: 'right', opacity:0.1}, 800, 'swing'); 

}); 
}); 

这里做了内联CSS是HTML代码,如果需要的话:

<div id="panelKS"> <!--the hidden panel --> 
    <div class="contentSideBarKS"> 
    </div> 
</div> 

<div id="tab2KS"> 
    <span id="ToolsTitleSpanOpenKS"> 
     <img id="bg" src="<?php echo $OUTPUT->pix_url('/buttons/opentools', 'theme')?>"/> 
    </span> 
    <span id="ToolsTitleSpanCloseKS"> 
     <img id="bg" src="<?php echo $OUTPUT->pix_url('/buttons/closetools', 'theme')?>"/> 
    </span> 
</div> 

你能告诉我该如何清除Inline css?

感谢

+1

尝试$( '格')removeAttr( '风格')。其中div表示删除其元素的元素 – Gopesh

+0

我在哪里放置此代码? – Mark

+0

你什么时候需要删除css? – Gopesh

回答

7

你可以在你的CSS使用!important

.test{ 
    right:800px !important;  
}  

该代码将使你的内联CSS忽略。

或者你可以得到DOM的属性style,使用:

$("div.test").attr("style",""); 

或者:

$("div.test").attr({style : ""}); 

这是你用你喜欢更多的解决方案。

+0

事情是,我不需要正确的元素CSS内联和外部。 另外我的其他问题是,谷歌浏览器和Firefox都正常工作。但在我的Internet Explorer侧面板不显示? 我该如何解决这个问题? – Mark

+0

这只是一个例子...,主要想法是使用!重要如果你想你的内联-css忽略.. :) owhh好..我看你已经得到答案:) .. – anztrax

+0

集成电路。无论如何感谢....你知道我怎么能解决Internet Explorer – Mark

0

也许这可以帮助您的问题,抱歉双岗(没有足够的字符原因)

<!doctype html> 
<html> 
    <head> 
     <style> 
      #panelKS{ 
       width : 500px; 
       background-color:#f0f; 
       display:none; 
      } 
      #tab2KS{ 
       width : 500px; 
       background-color:#fa0; 
       display:inline-block; 
       position:absolute; 
      } 
     </style> 
    </head> 
    <body> 
    </body> 
     <div id="panelKS"> <!--the hidden panel --> 
      <div class="contentSideBarKS"> 
       Testing 
      </div> 
     </div> 

     <!-- my assumtion is --> 
     <div id="tab2KS"> 
      <span id="ToolsTitleSpanOpenKS" value="1"> 
       <img id="bg" src="#" alt="image 1" title="image 1"/> 
      </span> 


    <span id="ToolsTitleSpanCloseKS" value="2"> 
      <img id="bg" src="#" alt="image 2" title="image 2"/> 
     </span> 
    </div> 

    <script src="scripts/jquery-1.9.0.min.js"></script> 
    <script> 
     $("#tab2KS").children().click(function(){ 
      $("#panelKS").css({display:"inline-block"}); 
      //after that in your css you could set transparency to 0 and do the animation 
     }); 
    </script> 
<body>