【问题标题】:Images don't always load when using jQuery to position and PHP to obtain URL使用 jQuery 定位和 PHP 获取 URL 时,图像并不总是加载
【发布时间】:2013-04-26 19:03:22
【问题描述】:

我一直是 stackoverflow 潜伏者,几乎总是在板上找到我的问题的答案(谢谢你)但是这个让我很难过......

我正在建立一个投资组合网站 .. 它使用 jQuery 来定位从 MySQL 数据库中提取的元素(图像) .. 非常简单......但是由于某种原因,图像并不总是加载或将加载情侣然后永久挂断,什么都不做……

页面在这里... http://www.spacecar.org/2013/

完成所有工作的 JS 文件在这里 http://www.spacecar.org/scripts/jquery.menu.js

有什么我没有看到的真正基本的东西吗?任何见解都将不胜感激......我知道我正在拨打很多电话来制定网站的效果功能,但是......啊!

谢谢

【问题讨论】:

  • 认为它与您的 jquery 图像加载器有关,名称为 krioImageLoader
  • 感谢您的回复!我尝试删除它,但不幸的是它对页面没有影响。图像仍未加载...
  • 您遇到的是小加载微调器还是损坏的图像?
  • 所以对我来说 .. 页面加载,然后微调器出现(有时),然后可能会加载一些图像但不是全部,然后它就坐在那里......如果你去要“查看源代码”,所有 HTML 都已正确加载......它只是没有显示在屏幕上......这让我发疯了!
  • 正确的是 jquery 正在检测图像是否加载。看起来在检测到图像已加载后,它会隐藏加载微调器。是你写的 jquery 还是你在网上找到的包?

标签: php javascript jquery mysql


【解决方案1】:

$( 'img' ).load( function(){ ... }); - 不是你可以信任的东西(在你的插件中我看到了这段代码)。在这里你可以看到原因: http://api.jquery.com/load-event/(从caveats字开始阅读)

以下是描述问题的小例子:

$( document ).ready( function(){
    $( 'img' ).load( function(){
       // this event going to fire only if document was ready after image was loaded; (very seldom, almost never)
       console.log( 'Fired?! You are lucky today!' );
    });

    $( document.body ).append( '<img src="http://stat19.privet.ru/lr/0b164d8151948d2fdedfbfdc420f5392?temp=2" id="some"/>' );
    $( '#some' ).load( function(){
        // this event will fire often, except of cases descripted in `load` event manual
        console.log( 'Huugh. Today have fired. But I don\'t know about tomorrow' );  
    });

  var temp = new Image;
  temp.src = 'http://photo.a42.ru/photos/92772/medium/11757.jpg';
  temp.onload = function(){
      // this event going to fire almost always except of cache issue with IE, that can be handled by skipping cache with `?nothing=random` appending to image URL
    console.log( 'Okay, okay! I\'ve fired' );
  }
  $( document.body ).append( temp );
});

你可以在这里运行它:http://jsfiddle.net/p6Cpy/

【讨论】:

  • 谢谢大家帮助我解决这个问题......确实是图像加载器......这个解决方案在这里......stackoverflow.com/a/8546076/2321573..似乎已经解决了所有问题......
猜你喜欢
  • 2015-07-24
  • 1970-01-01
  • 1970-01-01
  • 2018-07-05
  • 1970-01-01
  • 1970-01-01
  • 2018-12-19
  • 1970-01-01
  • 2016-10-09
相关资源
最近更新 更多