【JQuery外掛程式】撲克正反面翻牌效果

來源:互聯網
上載者:User

標籤:

裡面有兩個demo,支援X橫向和Y縱向翻轉兩個效果。

對元素的布局有一定的講究,需要分析一下demo的css。

預設翻轉速度為80,不要大於100ms。

<!DOCTYPE><html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>【JQuery外掛程式】撲克正反面翻牌效果</title><style>*{margin:0px;padding:0px;list-style:none;font-size: 16px;}</style></head><body><style>.demo1 {margin:10px; width: 200px;height: 100px;text-align: center;position: relative;}.demo1 .front{width: 200px;height: 100px;position:absolute;left:0px;top:0px;background-color: #000;color: #fff;}.demo1 .behind{width: 200px;height: 0px;position:absolute;left:0px;top:50px;background-color: #ccc;color: #000;display: none;}</style><h1>demo1 y軸 (css布局提示:背面預設隱藏 height為0 top是高度的一半也就是demo中間)</h1><div class="demo1"><div class="front">正面正面正<br/>面正面正面<br/></div><div class="behind">背面</div></div><div class="demo1"><div class="front">正面</div><div class="behind">背面</div></div><style>.demo2 {margin:10px; width: 200px;height: 100px;text-align: center;position: relative;}.demo2 .front{width: 200px;z-index: 1; height: 100px;position:absolute;left:0px;top:0px;background-color: #000;color: #fff;}.demo2 .behind{width: 0;height: 100px;z-index: 0;position:absolute;left:100px;top:0;background-color: #ccc;color: #000;}</style><h1>demo2 x軸(css布局提示:背面預設隱藏 width為0 left是寬度的一半也就是demo中間)</h1><div class="demo2"><div class="front">正面</div><div class="behind">背面</div></div><div class="demo2"><div class="front">正面</div><div class="behind">背面</div></div><script type="text/javascript" src="http://static.cnmo-img.com.cn/js/jquery144p.js"></script><script>(function($) {/*====================================================【JQuery外掛程式】撲克翻牌效果@auther LiuMing@blog http://www.cnblogs.com/dtdxrk/====================================================@front:正面元素@behind:背面元素@direction:方向@dis:距離@mouse: ‘enter‘ ‘leave‘ 判斷滑鼠移入移出@speed: 速度 不填預設速度80 建議不要超過100*/var OverTurnAnimate = function(front, behind, direction, dis, mouse, speed){/*判斷移入移出*/var $front = (mouse == ‘enter‘) ? front : behind,$behind = (mouse == ‘enter‘) ? behind : front;$front.stop();$behind.stop();if(direction == ‘x‘){$front.animate({left: dis/2,width: 0},speed, function() {$front.hide();$behind.show().animate({left: 0,width: dis},speed);});}else{$front.animate({top: dis/2,height: 0},speed, function() {$front.hide();$behind.show().animate({top: 0,height: dis},speed);});}};/*@demo$(‘.demo1‘).OverTurn(@direction, @speed);@direction(String)必選 ‘y‘ || ‘x‘ 方向@speed(Number)可選 速度*/$.fn.OverTurn = function(direction, speed) {       /*配置參數*/    if(direction!=‘x‘ && direction!=‘y‘){throw new Error(‘OverTurn arguments error‘);}    $.each(this, function(){    var $this = $(this),    $front = $this.find(‘.front‘),    $behind = $this.find(‘.behind‘),    dis = (direction==‘x‘) ? $this.width() :$this.height(),    s = Number(speed) || 80;/*預設速度80 建議不要超過100*/      $this.mouseenter(function() {  OverTurnAnimate($front, $behind, direction, dis, ‘enter‘, s);}).mouseleave(function() {  OverTurnAnimate($front, $behind, direction, dis, ‘leave‘, s);});    });};})(jQuery);/*外掛程式引用方法y*/$(‘.demo1‘).OverTurn(‘y‘,100);/*speed不填預設速度80 建議不要超過100*//*外掛程式引用方法x*/$(‘.demo2‘).OverTurn(‘x‘);</script></body></html>

  

【JQuery外掛程式】撲克正反面翻牌效果

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.