Guest User

Untitled

a guest
Jan 20th, 2019
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.14 KB | None | 0 0
  1. var onCssLoad = function (options, callback) {
  2. var body = $("body");
  3. var div = document.createElement(constants.TAG_DIV);
  4. for (var key in options) {
  5. if (options.hasOwnProperty(key)) {
  6. if (key.toLowerCase() === "css") {
  7. continue;
  8. }
  9. div[key] = options[key];
  10. }
  11. }
  12.  
  13. var css = options.css;
  14. if (css) {
  15. body.appendChild(div);
  16. var handle = -1;
  17. handle = window.setInterval(function () {
  18. var match = true;
  19. for (var key in css) {
  20. if (css.hasOwnProperty(key)) {
  21. match = match && utils.getStyle(div, key) === css[key];
  22. }
  23. }
  24.  
  25. if (match === true) {
  26. window.clearTimeout(handle);
  27. body.removeChild(div);
  28. callback();
  29. }
  30. }, 100);
  31. }
  32. }
  33.  
  34. onCssLoad({
  35. "id": <insert element CSS applies to>,
  36. css: <insert sample CSS styles>
  37. }, function () {
  38. console.log("CSS loaded, you can show the slideshow now :)");
  39. });
  40.  
  41. function getStyle(elem, prop) {
  42. return window.getComputedStyle(elem, null).getPropertyValue(prop);
  43. }
  44.  
  45. function checkStyle(elem, prop, callback) {
  46. while ( getStyle(elem, prop) !== 'computed' ) {
  47. // see explanation below
  48. }
  49. callback()
  50. }
  51.  
  52. function checkStyle(elem, prop, callback) {
  53. if ( getStyle(elem, prop) !== 'computed' ) {
  54. // see explanation below
  55. window.setTimeout( function() {checkStyle(elem, prop, callback);}, 100 )
  56. } else {
  57. callback()
  58. }
  59. }
  60.  
  61. $(function(){
  62. // this fn not waiting for images
  63. $('.selector-class')[0].style ;// this is your computed style OR...
  64. $('.selector-class').css(); // json representation of style;
  65. });
  66.  
  67. document.addEventListener( "DOMContentLoaded", function(){
  68. var computedStyle = document.querySelector('#yourElementId').style ;
  69. })
  70.  
  71. function getStyle(elem, prop) {
  72. return window.getComputedStyle(elem, null).getPropertyValue(prop);
  73. }
  74.  
  75. function checkStyle(elem, prop, callback) {
  76. while ( getStyle(elem, prop) !== 'computed' ) {
  77. // see explanation below
  78. }
  79. callback()
  80. }
Add Comment
Please, Sign In to add comment