I have JavaScript for three HTML sections, mm , ss and pp . These three fields are animated with each other ... If the contents of an external file changes, these fields are updated on my page. They are updated with animation.
If mm changes, then:
ss hiding thenpp hides thenmm hide then- divs are updated then
mm shows thenpp shows thenss shows then
If mm does not change, but pp does, then:
ss hiding thenpp hides then- divs are updated then
pp shows thenss shows then
If mm and pp do not change, but ss does, then:
ss hiding then- divs are updated then
ss shows then
This code works for me, but it is very cumbersome, and I wonder if there is a better way to do what I am doing:
if ($('#mm').html() != mm) { hideElem('.score'); setTimeout(function() { hideElem('.player'); setTimeout(function() { hideElem('.match'); setTimeout(function() { updateElems(); setTimeout(function() { showElem('.match'); setTimeout(function() { showElem('.player'); setTimeout(function() { showElem('.score'); }, inSpeed); }, inSpeed); }, outSpeed); }, outSpeed); }, outSpeed); }, outSpeed); } else if ($('#pp').html() != pp) { hideElem('.score'); setTimeout(function() { hideElem('.player'); setTimeout(function() { updateElems(); setTimeout(function() { showElem('.player'); setTimeout(function() { showElem('.score'); }, inSpeed); }, outSpeed); }, outSpeed); }, outSpeed); } else if ($('#ss').html() != ss) { hideElem('.score'); setTimeout(function() { updateElems(); setTimeout(function() { showElem('.score'); }, outSpeed); }, outSpeed); }
The reason for setTimeouts is all animations.
javascript jquery
Jason axelrod
source share