开发者

jquery animate is not working in chrome

开发者 https://www.devze.com 2023-04-05 10:54 出处:网络
my jquery animation code is working fine in IE and firefox, but it doesnt work in Chrome and safari. any suggestions?

my jquery animation code is working fine in IE and firefox, but it doesnt work in Chrome and safari. any suggestions?

this is my animation code for jquery

$('#menu ul li a').click(function (e) {

    /* On a thumbnail click */
    $('li.menuItem').removeClass('act').addClass('inact');
    $(this).parent().addClass('act');

    var pos = $(this).parent().prevAll().length; //.prevAll('.menuItem').length;
    pos = pos - 1;


    $('#slides').animate({ marginLeft: -position开发者_运维技巧s[pos] + 'px' }, 450);
    /* Start the sliding animation */

    e.preventDefault();
    /* Prevent the default action of the link */
});


if I remember well jQuery computes well without 'px' when animating or applying css for easier manipulation, and it is more logical because animating is calculation with numbers, not strings. Then isn't it a problem of css property ? Have you tried to set at least a 'position':'relative' or 'display':'block' or 'display':'inline-block' to the element you are animating. Because css needs that type of display for applying margin properties. Try animate 'left' instead of 'margin-left' for example, if it works, it comes from a needed css property for applying margin.


Use left instead of marginLeft.

0

精彩评论

暂无评论...
验证码 换一张
取 消