javascript - 当我使用 chrome 移动版时,div on.click 事件不起作用

标签 javascript jquery css google-chrome

我在 jquery 中有以下 div 元素:

this.$flipPages.find( '.box' ).on( 'click.flips', function( event ) {

    var $box            = $(this),
    $boxClose       = $( '<span class="box-close">close</span>' ),
    transitionProp  = {
        speed           : 450,
        timingfunction  : 'linear'
    },
    $overlay        = $( '<div class="overlay">close</div>' ).css( {
                        'z-index'               : 9998,
                        '-webkit-transition'    : 'opacity ' + transitionProp.speed + 'ms ' + transitionProp.timingfunction,
                        '-moz-transition'       : 'opacity ' + transitionProp.speed + 'ms ' + transitionProp.timingfunction
                    } ).prependTo( $( 'body' ) ),
    prop            = {
        width   : $box.outerWidth(true),
        height  : $box.outerHeight(true),
        left    : $box.offset().left,
        top     : $box.offset().top
    },
    $placeholder    = $box.clone().css( {
        'position'          : 'absolute',
        'width'             : prop.width,
        'height'            : prop.height,
        'left'              : prop.left,
        'top'               : prop.top,
        'zIndex'            : 9999,
        'overflow-y'        : 'auto',
        '-webkit-transition': 'all ' + transitionProp.speed + 'ms ' + transitionProp.timingfunction,
        '-moz-transition': 'all ' + transitionProp.speed + 'ms ' + transitionProp.timingfunction
    } )
    .insertAfter( $overlay )
    .end()
    .append( $boxClose.on( 'click.flips', function( event ) {

        $overlay.css( 'opacity', 0 );

        $placeholder.children().hide().end().removeClass( 'box-expanded' ).css( {
            width           : _self.windowProp.width,
            height          : _self.windowProp.height,
            'overflow-y'    : 'hidden'
        } );

        setTimeout( function() {
            $placeholder.css( {
                left    : prop.left,
                top     : prop.top,
                width   : prop.width,
                height  : prop.height,
                '-webkit-transition'    : 'all ' + transitionProp.speed + 'ms ' + transitionProp.timingfunction,
                '-moz-transition'   : 'all ' + transitionProp.speed + 'ms ' + transitionProp.timingfunction
            });
        }, 0 );

        }) ).children().hide().end()
            .on( 'webkitTransitionEnd.flips transitionend.flips OTransitionEnd.flips', function( event ) {

            if( $( event.target ).hasClass( 'box-expanded' ) ) { // expanding

                $(this).css( {
                    width   : '100%',
                    height  : '100%',
                    '-webkit-transition' : 'none',
                    '-moz-transition' : 'none'
                } ).children().fadeIn();

            }
            else { // collapsing

                $overlay.remove();
                $(this).remove();

            }

    });

    setTimeout( function() {

        $overlay.css( {
            opacity : 1
        } );

        $placeholder.addClass( 'box-expanded' ).css( {
            left    : 0,
            top     : 0,
            width   : _self.windowProp.width,
            height  : _self.windowProp.height
        });

    }, 0 );

} );

这个 .box 是一个有内容的 div,它是可点击的,虽然它适用于台式机和笔记本电脑版本的 chrome,但不适用于移动 chrome 版本。它适用于 safari android 版本。我使用 Kinetic,我听说在使用它时我必须做一些调整才能使其在 chrome for mobile 上运行。

这在 chrome 移动设备上不起作用有什么原因吗?

编辑:

我在这个函数中添加了一个警报,当我使用 chrome for desktop 时,它会打印出来,如果我使用 chrome mobile,它永远不会发出任何警报。它没有被调用。

最佳答案

你要搜索的是手机点击事件和桌面点击事件
这可能会起作用:

this.$flipPages.find( '.box' ).on( 'touchend click.flips', function( event ) {
   ...
});

关于javascript - 当我使用 chrome 移动版时,div on.click 事件不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25461933/

相关文章:

javascript - 如何将某些 HTML 的显示延迟到加载 javascript 之后

javascript - 我的 Chart.js Canvas 在 hide() 函数后消失

javascript - 我想要相同的表下拉值

javascript - 如何提高图像交叉淡入淡出性能?

php - 在谷歌地图中按纬度/经度删除标记

javascript - 设计 ES6 : appropriate way to identify group of classes

JQuery:使用 Javascript 事件作为内联属性是个好主意吗?

html - 使用图像作为容器?

html - 如何将文本放在图标下方?

css - Div 之间的空白