jQuery-按设置值增加属性 [英] jquery - Increment attribute by set value

查看:74
本文介绍了jQuery-按设置值增加属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个直到最近都运行良好的jQuery函数.

I have a jQuery function that has been running well until recently.

//Calculate width of slider container
var calc_width = 200 * $('.side_list_cont').length;
$("#op_slide").width(calc_width);


//Calculation for when to decrease margin for slide effect
$('#op_right').click(function(){
    var slidewidth = parseInt($('#op_slide').css('width'),10),
        getslideleft = parseInt($('#op_slide').css('margin-left'),10),
        slideleft = ((getslideleft - 200)*-1);
    if ( slideleft >= slidewidth ) {
    }
    else {
        $('#op_slide').animate({'margin-left': '-=200px'}, 200);
    }
});


//Calculation for when to increase margin for slide effect
$('#op_left').click(function(){
    var slidewidth = $('#op_slide').css('width'),
        slideleft = $('#op_slide').css('margin-left');
    if (slideleft == '0px') {
    }
    else {
        $('#op_slide').animate({'margin-left': '+=200px'}, 200);
    } 
});

我过去的工作很棒.突然之间,它没有增加左边距的值,而只是将其更改为200px-200px.当在.animate上查看jQuery的文档时,他们在此递增方法上的示例应能正常工作.

I used to work great. Then all of a sudden, it's not incrementing the margin-left value, but just changing it to either 200px or -200px. When looking at jQuery's docs on .animate, their example on this increment method works as it should.

推荐答案

您最近升级到jQuery 1.10.0了吗?如果是这样,相对的动画问题(例如.animate({'margin-left': '+=200px'})就是该版本中的一个错误,是今天在1.10.1中修复的.

Did you recently upgrade to jQuery 1.10.0? If so, the relative incremental animation issue (e.g. .animate({'margin-left': '+=200px'}) was a bug in that version that was just fixed today in 1.10.1.

请参阅: http://blog.jquery.com/2013/05/30/jquery-1-10-1-and-2-0-2-released/ 查看全文

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆