I am running the following code in jQuery to dynamically load a stylesheet. Its purpose is to allow users to load a custom stylesheet and change the appearance of the JavaScript widget:
this.loadStyleSheet = function(url){ $("<link rel='stylesheet' type='text/css' />").attr("href", url).appendTo("head"); }
For a second of a second, the screen looks unstable, because the correct style is applied to the widget only after loading the dynamic style sheet. To solve this problem, I need to know when the dynamic styles actually finished loading.
Although this question has been discussed before , none of the solutions apply in my case:
Any new ideas on this issue? Your help is greatly appreciated.
Expand my comment above if someone else needs an answer for this:
Javascript :
var style = $('<style type="text/css">'); $(document).append(style); style.load('/fetchstyle.php', { url: "http://somesite.com/style.css" }, function() { // The styles are loaded });
fetchstyle.php script :
<?php echo file_get_contents($_GET['url']);
, .
"load() IE, Firefox. - . BTW,.ready() , ."
,.load() firefox.
" - CSS setTimeout. , , CSS.
, , , , css, ?
: , changechange?
$(body).bind('propertychange', function(){ show_my_page_after_timeout(); });
, , , css, ( ), . , , ( css) , .
. , css. $. HoldReady jQuery document.ready. , css? onload . :
$.holdReady(true); $('head').append($('<link rel="stylesheet" type="text/css" onload="$.holdReady(false)"/>').attr('href','myCSS.css')); $(document).ready(function() { ...code here to execute after css loads })
It works in FF 16. Not tested in different versions or browsers. Also, I think the onload event in the link tag is purely HTML5.
Source: https://habr.com/ru/post/1770499/More articles:Update Linq's Many-Many Sql Attitude - c #What Perl web infrastructure should I use for a static HTML application? - htmlWhat does tstbklt () do from the jumbler tumblr booklet? - javascriptcross-browser asynchronous bootloader? - javascriptUIView Animation Misbehaves when changing iPad orientation - objective-cUIViewAnimationOptionTransitionCurlUp - ios?? оператор в sql - c#ExtJS grid - how to focus on the added row? - jsonPDF calculates glyph sizes - iosPHP creates secure PDF file - phpAll Articles