Skip to content

Instantly share code, notes, and snippets.

@jikanter
Created September 10, 2024 15:57
Show Gist options
  • Select an option

  • Save jikanter/b4a6a34f3945fe0226b9320a747670a5 to your computer and use it in GitHub Desktop.

Select an option

Save jikanter/b4a6a34f3945fe0226b9320a747670a5 to your computer and use it in GitHub Desktop.
[Other way to do flicker hide - no JQuery]
<style id="flickersuppression">
/* Add CSS to elements you want to hide */
#carousel {visibility:hidden !important}
</style>
<script type="text/javascript">
/*
This function will poll the DOM for a specified amount of time until a specific element is available in the DOM and once available, execute a callback function which can be used to change the content on the page. The arguments are:
t: A function which returns the DOM element you are looking for.
e: The callback function to execute after the element exists.
The function is currently configured to wait 3 seconds and check every 50ms for the DOM element, but this can be modified by changing the "n" variable (number of seconds to wait) and the "_" variable (how often to check).
*/
var _wait_for_element=function(t,e){this.wait_for_element_counter=this.wait_for_element_counter||0;var n=3,_=50,i=null;if("function"==typeof t){try{i=t()}catch(o){}if(i&&"function"==typeof e){this.wait_for_element_counter=0;try{e()}catch(o){}return}}i||_*this.wait_for_element_counter<1e3*n&&(this.wait_for_element_counter++,setTimeout(function(){_wait_for_element(t,e)},_))};
/* Call function above, which runs when your element exists */
_wait_for_element(
function(){
/* Add logic for finding a returning the element you're waiting for */
return document.getElementById('element_id');
},
function(){
/* Add your logic here to change content */
/* Remove flicker suppression CSS */
var css = document.getElementById('flickersuppression');
css.parentNode.removeChild(css);
}
);
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment