简体   繁体   English

使用jQuery在Chrome中更改图像不会加载

[英]Changing image in Chrome with jQuery don't load

I have this code: 我有以下代码:

$('#logo a img').attr('src', window.location.protocol + "//" + window.location.host + '/images/loader.gif');

It's jQuery. 是jQuery。 It is made to change the image to the loader, it works in IE and Firefox, but in Chrome it appears that: http://gyazo.com/6dad40741782b122cf621716ff2b86ec I've tried to load it with the url and Chrome finds the image, but it just don't load in the page. 它是通过将图片更改为加载程序而实现的,它可以在IE和Firefox中使用,但是在Chrome浏览器中似乎是: http : //gyazo.com/6dad40741782b122cf621716ff2b86ec我尝试使用url加载它,而Chrome找到了图片,但它不会加载到页面中。 What can be the reason? 可能是什么原因? It just works when you click 'Log in', I don't know why because it's the same function... Thank you so much! 它仅在您单击“登录”后才起作用,我不知道为什么,因为它具有相同的功能...非常感谢!

PS: Sorry for my bad english ;( PS:对不起,我英语不好;(

PS 2: I don't want to use CSS if it's possible, thanks PS 2:如果可能,我不想使用CSS,谢谢

Here's the live Demo, just click the logo (for example): http://www.sploonder.com/ 这是现场演示,只需单击徽标(例如)即可: http : //www.sploonder.com/

Why don't you preload the loader image before use it. 在使用加载器映像之前,为什么不预先加载它。

Just run this code when the document is ready. 准备好文档后,只需运行此代码即可。

$('<img>').attr('src', window.location.protocol + "//" + window.location.host + '/images/loader.gif');

And try it again. 然后再试一次。

我尝试了该解决方案(预加载图像),它有时可以工作,所以我不得不使用CSS。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM