jQuery幻灯片 – 想要随机但需要从相同的图像开始

所以我发现这个惊人的jQuery幻灯片名为Skitter。 这很棒! 所以我在我的最新项目中实现了它。 我得到了它@ http://thiagosf.net/projects/jquery/skitter/#documentation

是否有可能(如果是这样,我如何)随机显示图像但是始终从特定的图像开始? 例如,假设我想要在用户加载页面时显示的第一个图像是具有欢迎消息的特定图像。 但是对于那个“之后”的每个图像,它都是随机的。

我的头部中有“show_randomly:true”部分,我当前的幻灯片已成功随机化。 我只希望有一个“开始”的形象。

所以从它的主页,我做了“自定义function”,并将它给我的代码复制/粘贴到我的页面的头部…

         $(document).ready(function() { $(".box_skitter_large").skitter({ animation: "randomSmart", dots: true, preview: true, controls_position: "center", numbers_align: "right", hideTools: true, show_randomly: true, controls: true, interval: 5000, velocity: 0.5, }); });  

就像我说的那样,我有一个成功的幻灯片运行,它正在随机化图像。 只需要一种方法让它始终从列表中的一个特定图像开始。 谢谢!!!

据我所知,这不是Skitter脚本的function。 但是,您可以轻松添加它。 首先打开jquery.skitter.js文件(很难对现在使用的.min.js文件进行更改,以后可以随时将其最小化)。

找到以下行:

 if (this.settings.show_randomly) this.settings.images_links.sort(function(a,b) { return Math.random() - 0.5; }); 

紧接着,添加:

 /* START INITIAL FIXED IMAGE MOD */ if (this.settings.show_randomly) { /* Only use a fixed initial image if show_randomly is enabled */ /* The following function is used to move an item in an array from fromIndex to toIndex */ Array.prototype.move = function(fromIndex, toIndex) { this.splice(toIndex, 0, this.splice(fromIndex, 1)[0]); }; initialIndex = 0; /* The following function finds the desired initial image and stores it's location */ $.each(this.settings.images_links, function(index, item) { if (item[1].slice(0,9) == "[initial]") initialIndex = index; }); this.settings.images_links[initialIndex][1].replace("[initial]", ""); /* Removes the [initial] tag so the link works properly */ this.settings.images_links.move(initialIndex, 0); /* Move it to the front of the array so it's displayed first */ } /* END INITIAL FIXED IMAGE MOD */ 

然后,要声明初始(开始)图像,只需将[initial]添加到所需图像的href属性的开头即可。 假设您在脚本选项中启用了show_randomly,以下示例将始终以images / 003.jpg开头。

 
  • cube

  • cubeRandom

  • block

  • cubeStop

  • cubeHide

  • cubeSize

如果您想再次将其最小化,可以使用多种Internet服务,例如http : //www.minifyjavascript.com,http : //refresh-sf.com/yui或http://jscompress.com 。