预加载 CSS 图像 [英] Preloading CSS Images
问题描述
我有一个隐藏的联系表单,单击按钮即可部署.它的字段被设置为 CSS 背景图片,并且它们总是比被切换的 div 晚一点出现.
I have a hidden contact form which is deployed clicking on a button. Its fields are set as CSS background images, and they always appears a bit later than the div that have been toggled.
我在 <head>
部分使用了这个片段,但没有成功(在我清除缓存后):
I was using this snippet in the <head>
section, but with no luck (after I cleared the cache) :
<script>
$(document).ready(function() {
pic = new Image();
pic2 = new Image();
pic3 = new Image();
pic.src="<?php bloginfo('template_directory'); ?>/images/inputs/input1.png";
pic2.src="<?php bloginfo('template_directory'); ?>/images/inputs/input2.png";
pic3.src="<?php bloginfo('template_directory'); ?>/images/inputs/input3.png";
});
</script>
我使用 jQuery 作为我的库,如果我也可以使用它来安排这个问题会很酷.
I'm using jQuery as my library, and it would be cool if I could use it as well for arranging this issue.
感谢您的意见.
推荐答案
我可以确认我的原始代码似乎可以工作.我随便贴了一张走错路的图片.
I can confirm that my original code seems to work. I was casually sticking to an image with a wrong path.
这是一个测试:http://paragraphe.org/slidetoggletest/test.html
<script>
var pic = new Image();
var pic2 = new Image();
var pic3 = new Image();
pic.src="images/inputs/input1.png";
pic2.src="images/inputs/input2.png";
pic3.src="images/inputs/input3.png";
</script>
这篇关于预加载 CSS 图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!