2015-10-21 118 views
0

当复选框被选中时,表格从右侧滑动,而当复选框未被选中时,表格从左到右。如何让它从上到下或从下到上滑动?使用jQuery淡入淡出

$(document).ready(function() { 
    $('input[type="checkbox"]').click(function() {  
     if ($(this).prop("checked") == true) { 
      $('#loaddiv').fadeIn('slow', function() { 
       $(this).delay(2000).fadeOut('slow');      
      }); 
      $('#tbdata').hide(2500);//this code casing slide from right to left 
     } 
     else if ($(this).prop("checked") == false) { 
      $('#loaddiv').fadeIn('slow', function() { 
       $(this).delay(2000).fadeOut('slow'); 
      }); 
      $('#tbdata').show(2500);// this code causing slide from right to left 
     } 
    }); 
}); 

检查herer http://jsfiddle.net/z7rgsduv/

+0

可以在http://jsfiddle.net中显示此代码的工作示例吗?我看不出有什么理由让这个代码做任何事情? –

+0

如果您观察'$('#tbdata')。show(2500);',这里的延迟导致了表格。你可以忽略其余的代码。 –

回答

0

您可以使用slideUp()slideDown()

UPDATE

$(document).ready(function() { 
 

 
    $('input[type="checkbox"]').click(function() { 
 

 
     if ($(this).prop("checked") == true) { 
 
      $('#loaddiv').fadeIn('slow', function() { 
 
       $(this).delay(2000).fadeOut('slow'); 
 
       
 
      }); 
 
      $('#tbdata').show(); 
 
      $('#tbdata').animate({top:0}) 
 
     } 
 
     else if ($(this).prop("checked") == false) { 
 
      $('#loaddiv').fadeIn('slow', function() { 
 
       $(this).delay(2000).fadeOut('slow'); 
 
      }); 
 
      $('#tbdata').animate({top:-25},function(){ 
 
      \t $(this).hide() 
 
      }) 
 
     } 
 
    }); 
 
});
#tbdata{ 
 
    position:relative; 
 
    top:-25px; 
 
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<form id="form1" runat="server"> 
 
     <div id ="divloading" style="width:100%; height:100%"> 
 
      <img id="loaddiv" src="http://www.degruyterfabriek.nl/wp-content/uploads/2013/12/DGF_Redactie.jpg" style="width:200px" /> 
 
      <div id="div1" style="width:100%; height:100%; overflow:hidden"> 
 
       <table id="tbdata" > 
 
        <tr> 
 
        <th>First Name</th> 
 
        <th>Last Name</th> 
 
        <th>Company</th> 
 
        </tr> 
 
       </table> 
 
       <p><input type="checkbox" />Click to hide details</p> 
 
     </div> 
 
     </div> 
 
    </form>

+0

我只想滑动表格'$('#tbdata')。show(2500);'而不是加载跳跃。 –

+0

好吧,我添加一个幻灯片的顶部功能 –