久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

不直觀的 removeClass() 問題

Unintuitive removeClass() problem(不直觀的 removeClass() 問題)
本文介紹了不直觀的 removeClass() 問題的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我正在使用這個翻轉插件,代碼見這個小提琴.目標是一次翻轉一個盒子,例如單擊的第二個框應該 revertFlip() 前一個框.在動畫期間,我不希望其他框可點擊.我注意到 removeClass() 不起作用.

I'm using this flip plugin, see the code in this fiddle. The goal is to flip one box at a time, e.g. the second box clicked should revertFlip() the previous one. During the animation I don't want the other boxes to be clickable. I noted that the removeClass() is not working.

<div class='flippable'>I'm unflipped 1</div> 
...
<div class='flippable'>I'm unflipped 9</div> 


$('.flippable:not(.reverted)').live('click',function()
    {
        var $this = $(this);
        var $prevFlip = $('.reverted'); 
        var $allBoxes = $('.flippable');      

        $this.flip(
        {
            direction: 'lr',
            color: '#82BD2E',
            content: 'now flipped',
            onBefore: function()
            { 
                $prevFlip.revertFlip();
                $prevFlip.removeClass('reverted'); 
            },
            onAnimation: function () 
            { 
                $allBoxes.preventDefault();
            },
            onEnd: function()
            { 
                $this.addClass('reverted');
            }
         })
    return false;
    });

非常感謝您的建議和建議.

I'll appreciate a lot your advise and suggestions.


錯誤控制臺輸出: $allBoxes.preventDefault 不是函數

推薦答案

我相信這與 revertFlip() 調用 onBeforeonEnd<有關/代碼>.這會導致 addClassremoveClass 出現一些奇怪的現象.查看我修改后的示例:http://jsfiddle.net/andrewwhitaker/7cysr/.

I believe this has something to do with revertFlip() calling onBefore and onEnd. This is causing some weirdness with addClass and removeClass. Check out my modified example: http://jsfiddle.net/andrewwhitaker/7cysr/.

如果您打開 FireBug,您會看到 onBeforeonEnd 被多次調用,而我 認為 具有以下效果(我還沒有完全弄清楚發生了什么):

You'll see if you open up FireBug that onBefore and onEnd are called multiple times, with I think is having the following effect (I haven't exactly worked out what's going on):

  1. 對正常翻轉"的 onEnd 調用設置所需元素的還原類.
  2. 調用 onEnd 以實現恢復翻轉"操作,在調用 onEnd 時再次設置與上述相同的元素.
  1. The call to onEnd for the normal "flip" sets reverted class for the desired element.
  2. The call to onEnd for the "revert flip" action sets the same element as above again when onEnd is called.

這里有一個解決方法.我已經使用 onBegin 并簡化了 onEnd 因為我不確定 revertFlip() 調用發生了什么:

Here's a workaround. I've taken out using onBegin and simplified onEnd since I'm not exactly sure what's going on with the revertFlip() call:

$(function() {
    var handlerEnabled = true;
    $('.flippable:not(.reverted)').live('click', function() {
        if (handlerEnabled) {
            var $this = $(this);
            var $prevFlip = $('.reverted');
            var $allBoxes = $('.flippable');

            handlerEnabled = false;

            $prevFlip.revertFlip();
            $prevFlip.removeClass("reverted");
            $this.addClass("reverted");

            $this.flip({
                direction: 'lr',
                color: '#82BD2E',
                content: 'now flipped',
                onEnd: function() {
                    handlerEnabled = true;
                }
            });
        }
        return false;
    });
})

我正在使用布爾標志來啟用和禁用事件偵聽器.試試這個例子:http://jsfiddle.net/andrewwhitaker/bX9pb/.它應該像您在 OP 中描述的那樣工作(一次只能翻轉一個).

I'm using a boolean flag to enable and disable the event listener. Try out this example: http://jsfiddle.net/andrewwhitaker/bX9pb/. It should work as you described in your OP (only flipping one over at a time).

您的原始代碼 ($allBoxes.preventDefault()) 無效,因為 $allBoxes 是元素的集合.preventDefault 是 jQuery 事件對象 上的一個函數.

Your original code ($allBoxes.preventDefault()) is invalid, because $allBoxes is a collection of elements. preventDefault is a function on the jQuery event object.

這篇關于不直觀的 removeClass() 問題的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

jQuery/JavaScript Library for avatar creation?(用于創建頭像的 jQuery/JavaScript 庫?)
How to do following mask input problem?(如何做以下掩碼輸入問題?)
Issues Setting Value/Label Using DropKick Javascript(使用 DropKick Javascript 設置值/標簽的問題)
how to unit-test private methods in jquery plugins?(如何對 jquery 插件中的私有方法進行單元測試?)
stellar.js - configuring offsets / aligning elements for a vertical scrolling website?(stellar.js - 為垂直滾動網站配置偏移量/對齊元素?)
jQuery masked input plugin. select all content when textbox receives focus(jQuery 屏蔽輸入插件.當文本框獲得焦點時選擇所有內容)
主站蜘蛛池模板: 在线色网 | 国产特级毛片aaaaaa | 亚洲欧美日韩中文在线 | av国产精品| 中文天堂网 | 成人午夜激情 | 成年精品 | aaaaaa大片免费看最大的 | 久久一| 日本手机看片 | 亚洲一区二区三区四区五区午夜 | 久久久久国产精品午夜一区 | 亚洲日本成人 | 色婷婷国产精品综合在线观看 | 激情影院久久 | 久久久久无码国产精品一区 | 日韩欧美视频免费在线观看 | 99精品视频在线观看 | 精品一区欧美 | h视频在线观看免费 | 在线一区 | 亚洲一区 中文字幕 | 欧美专区在线 | 综合一区 | 国产精品96久久久久久 | 亚洲va欧美va人人爽午夜 | 亚洲国产精品一区二区第一页 | 国产一区二区三区在线视频 | 久久一起草| 成人在线观看免费爱爱 | 亚洲一区二区精品视频 | 久久国产精品偷 | 国产a级黄色录像 | 欧美成人免费电影 | 亚洲视频在线播放 | 国产91综合 | 一本在线| 欧美成人精品一区二区男人看 | 欧美日韩在线观看视频 | 中午字幕在线观看 | 四虎永久免费在线 |