首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >jQuery Orbit -如何制作随机幻灯片?

jQuery Orbit -如何制作随机幻灯片?
EN

Stack Overflow用户
提问于 2012-08-29 20:27:46
回答 1查看 1.4K关注 0票数 2

我为我的网站找到了一个很酷的幻灯片。

当页面加载时,第一张图片会出现在幻灯片中。

我想幻灯片显示随机显示一些图片时,页面加载。

Javascript代码:

代码语言:javascript
复制
 (function($) {
    $.fn.orbit = function(options) {

    var defaults = {  
    animation: 'fade',                  
    animationSpeed: 800,                
    timer: false,                       
    advanceSpeed: 4000,                 
    pauseOnHover: false,                
    startClockOnMouseOut: false,       
    startClockOnMouseOutAfter: 1000,    
    directionalNav: true,               
    captions: true,                     
    captionAnimation: 'fade',          
    captionAnimationSpeed: 800,        
    bullets: false,                     
    bulletThumbs: false,                
    bulletThumbLocation: '',           
    afterSlideChange: function(){}      
};

有什么想法吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-08-29 23:18:34

因此;开放源代码动态观察对象设置添加随机默认false:

代码语言:javascript
复制
defaults: {                                                                 
    animation: 'horizontal-push',     
    animationSpeed: 600,              // how fast animtions are               
    timer: true,                      // true or false to have the timer      
    advanceSpeed: 4000,               // if timer is enabled, time between transitions 
    pauseOnHover: false,              // if you hover pauses the slider       
    startClockOnMouseOut: false,      // if clock should start on MouseOut    
    startClockOnMouseOutAfter: 1000,  
    directionalNav: true,                 // manual advancing directional navs
    captions: true,                   // do you want captions?                
    captionAnimation: 'fade',             // fade, slideOpen, none            
    captionAnimationSpeed: 600,       // if so how quickly should they animate in
    bullets: false,                   
    bulletThumbs: false,              // thumbnails for the bullets           
    bulletThumbLocation: '',          // location from this file where thumbs will be
    afterSlideChange: $.noop,     // empty function                           
    fluid: false,             
    centerBullets: true,

    /////////////////////////// add Line
    random: false, // or true 
    ////////////////////////////

    },

在动态观察对象{loaded}方法后,添加到if (options.random) then随机:

代码语言:javascript
复制
loaded: function () {                                                       
    this.$element                                                             
        .addClass('orbit')                                                      
        .css({width: '1px', height: '1px'});                                    

    this.setDimentionsFromLargestSlide();                                     
    this.updateOptionsIfOnlyOneSlide();                                       
    this.setupFirstSlide();                                                   

    if (this.options.timer) {                                                 
        this.setupTimer();                                                      
        this.startClock();                                                      
    }                                                                         

    if (this.options.captions) {                                              
        this.setupCaptions();                                                   
    }                                                                         

    if (this.options.directionalNav) {                                        
        this.setupDirectionalNav();                                             
    }                                                                         

    if (this.options.bullets) {                                               
        this.setupBulletNav();                                                  
        this.setActiveBullet();                                                 
    }                                                                         


  //////////////////////////////// add Line                                                                   
  if (this.options.random)                                                  
      this.shift(this.Random.__init__()); 
  /////////////////////////////////////                                  

},

之后;添加动态观察对象新方法{Random}

代码语言:javascript
复制
    Random: {                                                                      

        __init__: function() {                                                     

            return this.math();                                                    
        },                                                                         

        math: function() {                                                       
            var bullets_count = (jQuery(".orbit-bullets li").length -1);           

            return (Math.floor(Math.random() * (bullets_count - 0 + 1)));          
        }                                                                                                                                               
},

放轻松..。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12177967

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档