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

In jquery dynamically changing css properties after checking some css properties

我想在另一个动画 div 到达 100px 时更改 div 的上边距,因为它的左侧 margin.I 已尝试以匿名方式进行功能,但它不工作。

代码如下:

(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();
})();`

我做的很简单,试试这个。

而不是

 $("#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);
 });