每10秒操作一次DOM元素

Manipulate DOM element every 10th second

本文关键字:一次 DOM 元素 10秒 操作      更新时间:2023-09-26

如何每隔10秒操作一个DOM元素?

我试过这样:

var endurance = angular.element('.progressbar').height();
var endurance2 = angular.element('.progressbar').css('height', endurance-25);                                       
window.setInterval(foo, 10000);
foo();
function foo()
{
    console.log("Update"); //This is running
    endurance2 = angular.element('.progressbar').css('height', endurance-25); //But not this
}

正如您所看到的,我的console.log("update");正在运行,但元素未更新。

有谁能帮我吗?

endurance始终相同,导致进度条始终具有相同的高度。在你的foo方法中重新计算endurance,你应该很好:

function foo()
{
    console.log("Update"); //This is running
    endurance = angular.element('.progressbar').height();
    endurance2 = angular.element('.progressbar').css('height', endurance-25);
}