在jquery中检查一些css属性后动态更改css属性

时间:2015-01-03 04:37:10

标签: jquery html css3

我希望在另一个动画div到达100px作为其左边距时更改div的上边距。我已尝试在匿名函数中执行此操作,但它无法正常工作。

以下是代码:

(function (){
 "use strict";

 var app = WinJS.Application;
 var activation = Windows.ApplicationModel.Activation;
 var animatedNumber;


 app.onactivated = function (args) {
    if (args.detail.kind === activation.ActivationKind.launch) {
        if (args.detail.previousExecutionState !==   activation.ApplicationExecutionState.terminated) {

            animatedNumber = parseInt(Math.random()*10);
            document.getElementById("animatedNumber").innerHTML = animatedNumber;
            $("#animatedNumber").animate({ marginLeft: '900px' },1000);


                if (parseInt($("#animatedNumber").css("marginLeft"))>= 100)
                    $("#A1").animate({ marginTop: '-=40px' })

        } else {
            // TODO: This application has been reactivated from suspension.
            // Restore application state here.
        }
        args.setPromise(WinJS.UI.processAll());
    }
};

app.oncheckpoint = function (args) {

};

app.start();
})();`

1 个答案:

答案 0 :(得分:0)

我说得很简单,试试这个。

而不是



 $("#animatedNumber").animate({
   marginLeft: '900px'
 }, 1000);


 if (parseInt($("#animatedNumber").css("marginLeft")) >= 100) {
   $("#A1").animate({
     marginTop: '-=40px'
   })
 }




试试这个



 $("#animatedNumber").animate({
   marginLeft: '100px'
 }, 150, function() {

   // DO the margin top changes
   $("#A1").animate({
     marginTop: '-=40px'
   });

   //Now complete the rest of the animation
   $(this).animate({
     marginLeft: '800px'
   }, 750);
 });