简体   繁体   English

Laravel/FancyTree 中 Jquery 对 CSS 所做的更改仅反映在 function 的末尾

[英]Changes made by Jquery to CSS in Laravel/FancyTree is only reflected at the end of the function

I currently have a fancy tree where when activating a node, it will run through a bunch of ajax/backend code which consumes time.我目前有一个花哨的树,当激活一个节点时,它将运行一堆消耗时间的 ajax/后端代码。

Desired outcome: When clicking on a node, the active event handler should catch the event and display a loading icon until all the following code is completed before the loading icon is removed however, the CSS changes made by the jquery is not running until after the function is already completed even though the jquery command has already been called prior to the additional set of ajax and backend code.期望的结果:单击节点时,活动事件处理程序应捕获事件并显示加载图标,直到在删除加载图标之前完成以下所有代码然而,jquery 所做的 CSS 更改直到之后才运行function 已经完成,即使在附加的 ajax 和后端代码集之前已经调用了 jquery 命令。 This results in the loader not being reflected at all.这导致加载程序根本没有被反映。

Poor solution: Setting a windows timeout between the toggling of the visibility of the loader allows the loader to actually be reflected onto the screen before removing it again.糟糕的解决方案:在加载程序的可见性切换之间设置 windows 超时允许加载程序在再次删除之前实际反映到屏幕上。

activate: function(event, d) {
console.log('make loader appear');
 $('#loader').css('display','block')
//bunch of random code here
$('#loader').css('display','none')
}

尽管在后端代码之前和之后调用了jquery代码,但加载器从未出现过

I think that probably because after you show the loading indicator you hide it right away.我认为这可能是因为在您显示加载指示器后,您会立即将其隐藏。

See your code in event activate function:在事件激活 function 中查看您的代码:

$('#loader').css('display','block') //bunch of random code here $('#loader').css('display','none')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM