Joh*_*kel 4 performance cursor angularjs
我有很多嵌套的ng-repeat的复杂页面。$ apply函数可能需要几秒钟。在此期间,浏览器已挂起,用户无法执行任何操作。
出于礼貌,我想在$ apply运行时将鼠标指针更改为沙漏。我怎样才能做到这一点?
诀窍是更改游标(使用addClass),然后在超时后调用慢速代码,然后将游标更改回正常。
var mybody = angular.element(document).find('body');
mybody.addClass('waiting'); // set cursor to hourglass
setTimeout(function() {
doSlowStuff();
$scope.$apply();
mybody.removeClass('waiting'); // set cursor to normal
}, 0);
Run Code Online (Sandbox Code Playgroud)
您必须在超时中执行慢速播放,以便addClass在慢速播放开始之前应用。
CSS只是
.waiting { cursor: wait; }
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4330 次 |
| 最近记录: |