在触发JQuery幻灯片之前加载所有图像

 浩斯科技 发布于 2023-01-15 17:13

我修改了Visual Idiot的Unslider(http://unslider.com/)以适应基于图像比例的多宽度幻灯片,但是在这个过程中,我遇到了一个错误导致幻灯片加载为微小的缩略图(我认为在图像没有一直加载的情况下).这是问题#1.所以我试图等到所有图像都加载完毕.但我还没有找到成功做到这一点的方法.这是问题#2.

这是我在Unslider init()函数中添加的代码:

_.init = function(el, o) {
  //  Check whether we're passing any options in to Unslider
  _.o = $.extend(_.o, o);

  _.el = el;
  _.ul = el.find(_.o.items);
  _.max = [el.outerWidth() | 0, el.outerHeight() | 0];
  _.max = [100, 100];
  _.li = _.ul.find(_.o.item).each(function(index) {
    var me = $(this);
    var an_image = me.find('img');
    an_image.load(function() {
      width = an_image[0].naturalWidth,
      height = an_image[0].naturalHeight;

      setSlideHeight(an_image, width, height, 300, 20);
      if ( an_image.parent().parent().is(":last-child") ) {

        _.el.css("width", 900);
      }
    })  

    //  Set the max values
    //if (width > _.max[0]) _.max[0] = width;
    //if (height > _.max[1]) _.max[1] = height;
  });

这里是我的Ruby部分内容,脚本内联用于在加载所有图像时触发Unslider.

<% if @page.cap_gallery_images.any? %>
  
<% end %>

问题是看起来图像加载处理程序并非全部触发.在我正在使用它的页面的上下文中查看它:http://penumbra-2.herokuapp.com/education

撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有