jquery - 在检查某些 css 属性后,在 jquery 中动态更改 css 属性

标签 jquery html css

我想在另一个动画 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();
})();`

最佳答案

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

代替

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

关于jquery - 在检查某些 css 属性后,在 jquery 中动态更改 css 属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27751783/

相关文章:

javascript - 使用 jQuery 获取 Asp 控件 ID

javascript - 按类或 div 对元素进行 Jasmine 测试

javascript - chrome 和 firefox 之间的 window.innerWidth 不同?

css - 将全局字体应用于 volusion 模板

javascript - 在提交表单之前显示一个 css 弹出窗口

jquery - 调整大小时的菜单过渡

javascript - 悬停时使用 jQuery SlideDown/slideUp,如何等待上一张幻灯片完成?

javascript - 从 html 页面调用文件 jQuery 文件

javascript - 如何在 CKEditor 中修改元素

html - 在图例元素中包装标签元素