jQuery控制的不同方向的滑動(橫向滑動等)

來源:互聯網
上載者:User

標籤:style   blog   http   java   color   os   

引入jquery.js,複製以下代碼,即可運行。

 

Css代碼  
  1. <style type="text/css">  
  2. .slide {  
  3.     position: relative;  
  4.     height: 200;  
  5.     lightyellow;  
  6. }  
  7.   
  8. .slide .inner {  
  9.     position: absolute;  
  10.     left: 0;  
  11.     bottom: 0;  
  12.     height: 100;  
  13.     lightblue;  
  14.     width: 100%  
  15. }  
  16. </style>  

 

 1、slidetoggle() 交替slidedown(),slideup()

 

Html代碼  
  1. <div id="slidebottom" class="slide">  
  2.     <button>  
  3.         slide it  
  4.     </button>  
  5.     <div class="inner">  
  6.         Slide from bottom  
  7.     </div>  
  8. </div>  

 

Js代碼  
  1. $(‘#slidebottom button‘).click(function() {  
  2.   $(this).next().slideToggle();  
  3. });  

 

 

2、左側橫向交替滑動 Animate Left 

 

Html代碼  
  1. <div id="slidewidth" class="slide">  
  2.     <button>  
  3.         slide it  
  4.     </button>  
  5.     <div class="inner">  
  6.         Slide from bottom  
  7.     </div>  
  8. </div>  

 

Js代碼  
  1. $("#slidewidth button").click(function(){  
  2.  $(this).next().animate({width: ‘toggle‘});  
  3. });  

 

 3、左側橫向交替滑動 Animate Left Margin (非隱藏)

 

Html代碼  
  1. <div id="slideleft" class="slide" style="width: 50%;float: right">  
  2.     <button>  
  3.         slide it  
  4.     </button>  
  5.     <div class="inner">  
  6.         Slide from bottom  
  7.     </div>  
  8. </div>  

 

Js代碼  
  1. $("#slideleft button").click(function(){  
  2.  var $lefty = $(this).next();  
  3.  $lefty.animate({  
  4.   left:parseInt($lefty.css(‘left‘),10)==0 ? -$lefty.outerWidth() : 0  
  5.  });  
  6. });  
 

 

4、右側橫向滑動Slide to right

 

Html代碼  
  1. <div id="slidemarginleft" class="slide" style="width: 60%;float: left">  
  2.     <button>  
  3.         slide it  
  4.     </button>  
  5.     <div class="inner">  
  6.         Slide from bottom  
  7.     </div>  
  8. </div>  

  

Js代碼  
  1. $("#slidemarginleft button").click(function(){  
  2.  var $marginlefty = $(this).next();  
  3.  $marginlefty.animate({  
  4.   marginLeft:parseInt($marginlefty.css(‘marginLeft‘),10)==0 ? $marginlefty.outerWidth() : 0  
  5.  });  
  6. });  
 

 

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.