2012-03-24 106 views
0

我有兩個從右向左滑動的div。我在使用名爲「箭頭」的分隔線時遇到困難,並且只向左側滑動名爲「內部」的分隔線。Jquery水平滑動標籤機制

<script language="javascript" src="http://code.jquery.com/jquery-1.5.2.js"></script> 
<script language="javascript"> 
$(document).ready(function() { 
     var out = 0; 
     $("#arrow").click(function(){ 
     if(out==0) 
     { 
      $("#inner").animate({marginRight: "0px"}, 500); 
      out=1; 
     } 
    else 
     { 
     $("#inner").animate({marginRight: "-100px"}, 500); 
     out=0; 
     } 
    }); 
}); 
</script> 

<div style="background-color: rgb(204, 204, 204); height: 300px; width: 300px; overflow: hidden;"> 
    <div id="inner" style="height: 100px; width: 100px; background-color: rgb(0, 204, 102); float: right; margin-right:-100px;" >Form is here</div> 

    <div id="arrow" style="height: 100px; width: 50px; background-color: rgb(255, 0, 0); float: right; cursor: pointer;" >Arrow is here</div> 


</div> 

回答

3

試試這個:

<div style="background-color: rgb(204, 204, 204); height: 300px; width: 300px; overflow: hidden; position: relative;"> 
<div id="inner" style="height: 100px; width: 100px; background-color: rgb(0, 204, 102); float: right; margin-right:-100px;" >Form is here</div> 

<div id="arrow" style="height: 100px; width: 50px; background-color: rgb(255, 0, 0); float: right; cursor: pointer; position: absolute; top: 0; right: 0;" >Arrow is here</div> 


</div> 
+0

感謝隊友!像我想要的那樣完美地工作。 – CodingWonders90 2012-03-24 04:16:20