PHPでいくつかのCSSファイルが生成されています。javacriptイベントに表示する前にファイルをプレロードする
クリックイベントで現在のCSSファイルを変更します。
しかし、それは各変更の間に厄介な白いフラッシュ効果を作ります(それらの最初の読み込み時にのみ、それらがキャッシュにあり、悪影響はありません)。
クリックイベントでこのCSSファイルをどのようにプリロードできますか?
$('.button').click(function(){
// Here I would like to preload the file
...
// Here I display it
$("#css").attr("href","css.php?id="+$(this).attr('id'));
});
EDIT>ソリューション
/* HTML File */
<link type="text/css" rel="stylesheet" href="css.php?id=1" id="css"/>
<link type="text/css" href="css.php?id=2" id="nextcss"/>
/* JS file */
$('.button').click(function(){
// Preload the file
$("#nextcss").attr("href","css.php?id="+$(this).attr('id'));
/* Here a lot of code with ajax...*/
// Here I display it
$("#css").attr("href","css.php?id="+$(this).attr('id'));
});
あなたはjsfiddle.netでデモを作ることができます – Rafay
私の質問にはデモが必要ないと思います...このスクリプトは動作しますが、プリロードを追加したいだけです – Valky