Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. function updateLog(){
  2. $.get('getLog.php',
  3. function(response){
  4. $('#container-log').each(function(){
  5. // get DOM element
  6. var div = $(this);
  7. //$(this).html("Hejsa");
  8. var scrolledDown = false;
  9. // check if div is scrolled down
  10. if((div.scrollTop - div.scrollHeight) < 12 && (div.scrollTop - div.scrollHeight) > -12){
  11. scrolledDown = true; // if already near bottom
  12. }
  13. var wasEmpty = false;
  14. if($(this).text().length<12){
  15. // div doesnt overflow
  16. wasEmpty = true;
  17. }
  18.  
  19. if(response){
  20. $(this).html(response);
  21. }
  22. else{
  23. $(this).html("");
  24. }
  25. if(scrolledDown || wasEmpty){
  26. // scroll divs down to the last line after refresh
  27. div.scrollTop = div.scrollHeight;
  28. }
  29. });
  30. }
  31. );
  32. };
  33. $(function(){
  34. updateLog();
  35. setInterval("updateLog()", 5000);
  36. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement