3

我在jQuery中使用翻转插件来翻转给定的 div。

代码(重用某人的代码)在您单击一个元素后翻转它。

我有几张图片,通过使用此功能,我正在尝试创建动画。我正在使用jQuery单击这些图像。然而问题是,即使用户可以单击图像并再次翻转我不想要的图像。

我尝试使用CSS属性:

    body{pointer-events:none;}

这可行,但在我完成动画后我无法使用jQuery禁用它。我试过:

    $('body').css('pointer-events','normal');

我重用的代码是:

$(document).ready(function() { /* The following code is executed once the DOM is loaded */


    $('.sponsorFlip').bind("click", function() {

        // $(this) point to the clicked .sponsorFlip element (caching it in elem for speed):
        var elem = $(this);

        // data('flipped') is a flag we set when we flip the element:
        if (elem.data('flipped')) {
            // If the element has already been flipped, use the revertFlip method
            // defined by the plug-in to revert to the default state automatically:
            elem.revertFlip();

            // Unsetting the flag:
            elem.data('flipped', false)
        }
        else {
            // Using the flip method defined by the plugin:
            $(this).unbind("click");
            $(this).unbind("click");
            $(this).unbind("click");
            elem.flip({
                direction: 'lr',
                speed: 350,
                onBefore: function() {
                    // Insert the contents of the .sponsorData div (hidden from view with display:none)
                    // into the clicked .sponsorFlip div before the flipping animation starts:

                    elem.html(elem.siblings('.sponsorData').html());
                }
            });

            // Setting the flag:
            elem.data('flipped', true);


        }
    });

});

我尝试添加

    $('.sponsorFlip').unbind("click");

它也不起作用。

4

3 回答 3

3
$('.sponsorFlip').on('click', function(e) {
   // for a click event by mouse has e.clienX/e.clientY 
   if(e.clientX){
      // then click by mouse
   } else {
      // triggered 
   }
});

演示(见控制台)

为您的代码

$('.sponsorFlip').bind('click', function(e) {
   // for a click event by mouse has e.clienX/e.clientY 
   if(e.clientX){
      // then click by mouse
   } else {
      // triggered 
   }
});

演示(见控制台)

于 2012-06-02T13:56:49.103 回答
0

将其分配给点击事件,然后模拟点击,然后取消分配点击事件似乎有点hack。为什么不直接创建一个翻转元素的函数呢?

var options = {...};
$(element).flip(options);
于 2012-06-02T14:15:35.607 回答
0

为了快速解决,只需尝试删除这些行:

 // If the element has already been flipped, use the revertFlip method
        // defined by the plug-in to revert to the default state automatically:
        elem.revertFlip();

        // Unsetting the flag:
        elem.data('flipped', false)
于 2012-06-02T14:29:35.650 回答