2014-08-28 38 views
0

早上好!以下是(我不知道最好的)使用jQuery插件Flip!的jQuery代碼。原來的翻轉火很好,但恢復翻轉不會爲我的生活發揮作用。我試過很多不同的東西,但都沒有成功。這是我目前擁有的。使用jQuery翻轉,無法恢復翻轉起火

任何幫助將不勝感激!

$('.flip1').bind("click",function(){ 
     var elem = $(".toflip"); 
     if(elem.data('flipped')){ 
      elem.revertFlip(); 
      elem.data('flipped',false) 
     } else { 
      elem.flip({ 
       direction:'lr', 
       dontChangeColor: true, 
       onBefore: function(){ 
        elem.html(elem.siblings('#flip1Data').html()); 
       } 
      }); 
      elem.data('flipped',true); 
     } 
    }); 
    $('.flip2').bind("click",function(){ 
     var elem = $(".toflip"); 
     if(elem.data('flipped')){ 
      elem.revertFlip(); 
      elem.data('flipped',false) 
     } else { 
      elem.flip({ 
       direction:'lr', 
       dontChangeColor: true, 
       onBefore: function(){ 

        elem.html(elem.siblings('#flip2Data').html()); 

       } 
      }); 
      elem.data('flipped',true); 
     } 
    }); 
    $("#flip1back").bind("click",function(){ 
     $('.toflip').revertFlip(); 
     return false; 
    }); 
    $("#flip2back").bind("click",function(){ 
     $('.toflip').revertFlip(); 
     return false; 
    }); 
+0

您的最終目標是在點擊上綁定翻轉,或者它是中間步驟,即在鼠標懸停時翻轉並在鼠標上翻轉回來?在這種情況下,我想建議你這個代碼:http://davidwalsh.name/css-flip(純CSS翻轉)。 – Giorgio 2014-08-28 15:08:08

+0

先生,這在點擊...從來沒有懸停或任何類型的東西。此外,這需要在IE8中工作 – 2014-08-28 15:33:18

回答

0

以下代碼執行左轉和右轉。如果您想更改翻轉方向,只需更改JS代碼上的direction屬性即可。不要忘記上傳必要的JS文件到你的文件夾中(你可以在HTML代碼的底部看到它們)。這是鏈接到working example

CSS:

.button { 
    display:inline-block; 
    padding:10px; 
    color:#fff; 
    cursor:pointer; 
    margin-top:40px; 
} 
.button#left { 
    background-color:green; 
} 
.button#revert { 
    background-color:red; 
    display:none; 
} 
#flipbox { 
    width: 500px; 
    height: 200px; 
    line-height: 200px; 
    background-color: #ff9000; 
    font-family: 'ChunkFive Regular', Tahoma, Helvetica; 
    font-size: 2.5em; 
    color: #ffffff; 
    text-align: center; 
} 

HTML:

<div id="flipbox">front content</div> 
<div class="button" id="left">left</div> 
<div class="button" id="revert">revert</div> 


<!-- JavaScript at the bottom for fast page loading --> 
<script type="text/javascript" src="jquery.min.js"></script> 
<script type="text/javascript" src="jqueryui.min.js"></script> 
<script type="text/javascript" src="jquery.flip.min.js"></script> 

<script type="text/javascript"> 
    $(function(){ 

     $("#left").bind("click",function(){ 
      var $this = $(this); 
      $("#flipbox").flip({ 
       direction: "rl", 
       color: "#39AB3E", 
       content: "back content", 
       onBefore: function(){$("#revert").css('display','inline-block');} 
      }) 
      return false; 
     }); 

     $("#revert").bind("click",function(){ 
      $("#flipbox").revertFlip(); 
      return false; 
     }); 

    }); 
</script> 

編輯

撤銷按鈕只顯示後第一次離開翻轉:有沒有辦法恢復倒裝如果你還沒有做到這一點:)代碼和工作國王的例子是最新的。

+0

我已經使用你的代碼,但恢復STILL不會觸發。 – 2014-08-28 16:28:40

+0

添加了工作示例的鏈接,並且更新後的代碼僅在第一次翻頁後顯示還原按鈕。現在工作正常。 – Giorgio 2014-08-28 17:58:02

+0

@NickMcCally:現在有效嗎?請提供一些反饋。 – Giorgio 2014-08-29 07:27:13