jQuery动画不适用于触摸事件

时间:2012-11-22 19:45:09

标签: jquery javascript-events jquery-animate touch-event

在以下代码中,$('#slidemenu-container').animate(...)无效:

$(document).live('touchend', function(event, data) {
    var container = $("#slidemenu-container");
    var container2 = $("#bg-yellow-id");

    if (container.has(event.target).length === 0 && container2.has(event.target).length === 0 && settings.katMenuVisible) {

        // workaround because showHide(...) with animate isnt working
        var left = '-=' + settings.listSlideWidth + 'px';
        $("#show-hide-kat").css({
            'background-image': "url('" + yiiBaseUrl + "/images/NAVbutton_opennav.png')"
        });

        $('#slidemenu-container').animate({
            left: left,
        }, settings.duration, function() {

        });

        settings.katMenuVisible = !settings.katMenuVisible;

    }
});

如果我使用.css()函数修改left属性,它会起作用:

$(document).live('touchend', function(event, data) {
    var container = $("#slidemenu-container");
    var container2 = $("#bg-yellow-id");

    if (container.has(event.target).length === 0 && container2.has(event.target).length === 0 && settings.katMenuVisible) {

        // workaround because showHide(...) with animate isnt working
        var left = '-=' + settings.listSlideWidth + 'px';
        $("#show-hide-kat").css({
            'background-image': "url('" + yiiBaseUrl + "/images/NAVbutton_opennav.png')"
        });

        container.css({
            'left': left
        });

        settings.katMenuVisible = !settings.katMenuVisible;

    }
});

有什么问题?我尝试了一切,但是动画仍然没有用。

感谢您的帮助。

1 个答案:

答案 0 :(得分:1)

也许尝试更简单的事情: .animate({“left”:“+ = 50px”},“slow”);

顺便说一下,我不知道你想要做什么,你试图让它切换到左边和动画?让它出现?