Jquery水平滑动标签机制

时间:2012-03-24 03:52:59

标签: javascript jquery html javascript-events

我有两个从右到左滑动的div。我遇到了一个名为“箭头”的div留在原地的困难,只是向左滑动了名为“内部”的div。

<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>

1 个答案:

答案 0 :(得分: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>