www.webdeveloper.com
Results 1 to 5 of 5

Thread: Adding an auto scroll

Hybrid View

  1. #1
    Join Date
    Jun 2013
    Posts
    3

    Adding an auto scroll

    Can anyone help me add and automatic scrolling effect to the following javascript. This code is on an older site using jquery 1.4.3. I was hoping it was just something I could simply add to this existing js so I don't have to redo the entire slideshow. Thanks!

    Code:
    <script type="text/javascript">
    $(document).ready(function() {
    // Save the jQuery objects for later use.
    var outer	= $("#preview_outer");
    var arrow	= $("#arrow");
    var thumbs	= $("#thumbs span");
    
    var preview_pos;
    var preview_els	= $("#preview_inner div");
    var image_width	= preview_els.eq(0).width(); // Get width of imaages
    
    // Hook up the click event
    thumbs.click(function() {
    // Get position of current image
    preview_pos = preview_els.eq( thumbs.index( this) ).position();
    
    // Animate them!
    outer.stop().animate( {'scrollLeft' : preview_pos.left},	500 );
    arrow.stop().animate( {'left' : $(this).position().left },	500 );
    });
    
    // Reset positions on load
    arrow.css( {'left' : thumbs.eq(0).position().left } ).show();
    outer.animate( {'scrollLeft' : 0}, 0 );
    
    // Set initial width
    $("#preview_inner").css('width', preview_els.length * image_width);
    });
    </script>

  2. #2
    Join Date
    Jun 2004
    Location
    Portsmouth UK
    Posts
    2,709
    please provide a link to the page with the script
    Vic

    God loves you and will never love you less.

    http://www.vicsjavascripts.org/Home.htm
    If my post has been useful please donate to http://www.operationsmile.org.uk/

  3. #3
    Join Date
    Jun 2013
    Posts
    3

    Sorry, guess that would have helped

    Quote Originally Posted by vwphillips View Post
    please provide a link to the page with the script
    http://millerbevco.com/

  4. #4
    Join Date
    Jun 2004
    Location
    Portsmouth UK
    Posts
    2,709
    using your current HTML and CSS

    remover your current script

    and position this immediately before the </BODY> tag

    Code:
    // Slider (12-June-2013)
    // by Vic Phillips - http://www.vicsjavascripts.org.uk/
    
    
    var zxcSlider={
    
     Next:function(id,ud){
      var o=this['zxc'+id],ud=(typeof(ud)=='number'&&ud<0?-1:1);
      if (o){
       o.ud=ud;
       this.rotate(o,o.cnt+ud);
      }
     },
    
     GoTo:function(id,nu){
      var o=this['zxc'+id];
      if (o&&o.ary[nu]){
       o.ud=nu>o.cnt?1:-1;
       this.rotate(o,nu)
      }
     },
    
     Auto:function(id,ms){
      var o=this['zxc'+id],oop=this;
      if (o){
       o.to=setTimeout(function(){ oop.rotate(o,true); },ms||200);
      }
     },
    
     Pause:function(id){
      var o=this['zxc'+id];
      if (o){
       clearTimeout(o.to);
      }
     },
    
     init:function(o){
      var id=o.SliderID,ms=o.Animate,ud=o.Direction,hold=o.Hold,srt=o.AutoStart,add=o.AddEvents,cls=o.ThumbsClass,p=document.getElementById(id),sd=p?p.getElementsByTagName('DIV')[0]:null,tp=document.getElementById(o.ThumbsID);;
      if (p&&sd){
       var clds=sd.childNodes,ary=[],thumbs=[],e,z0=0,z1=0,z2=0;
       for (;z0<clds.length;z0++){
        if (clds[z0].nodeType==1){
         clds[z0].style.position='absolute';
         clds[z0].style.zIndex=ary.length>0?'0':'2';
         clds[z0].style.left=(ary.length>0?3000:0)+'px';
         clds[z0].style.top='0px';
         ary.push([clds[z0],'left']);
        }
       }
       if (tp){
        clds=tp.childNodes;
        for (;z1<clds.length;z1++){
         if (clds[z1].nodeType==1){
          this.addevt(clds[z1],'mouseup','GoTo',id,thumbs.length);
          this.addevt(clds[z1],'mouseover','mse',id,clds[z1]);
          this.addevt(clds[z1],'mouseout','mse',id,clds[z1]);
          thumbs.push(clds[z1]);
         }
        }
       }
       this['zxc'+id]={
        id:id,
        ary:ary,
        lgth:ary.length-1,
        thumbs:thumbs,
        cls:cls,
        ct:thumbs[0],
        ms:ms,
        hold:typeof(hold)=='number'&&hold>0?hold:ms*4,
        cnt:0,
        lst:0,
        ud:typeof(ud)=='number'&&ud<0?-1:1
       }
       if (add instanceof Array){
        for (;z2<add.length;z2++){
         if (add[z2]&&add[z2][0]){
          o=document.getElementById(add[z2][0]);
          e=add[z2][1];
          if (o&&(e=='mouseup'||e=='mousedown'||e=='mouseover'||e=='mouseout'||e=='click')&&this[add[z2][2]]){
           this.addevt(o,e,add[z2][2],id,add[z2][3]);
          }
         }
        }
       }
       typeof(srt)=='number'&&srt>0?this.Auto(id,srt):null;
      }
     },
    
     rotate:function(o,auto){
      this.Pause(o.id);
      var c=o.cnt,d=new Date(),sz;
      o.ary[o.lst][0].style.zIndex='0';
      o.ary[c][0].style.zIndex='1';
      o.lst=c;
      o.auto=auto===true;
      c=auto===true?c+=o.ud:auto;
      c=c<0?o.lgth:c>o.lgth?0:c;
      o.ary[c][0].style.zIndex='2';
      sz=o.ary[o.ud>0?o.cnt:c][0].offsetWidth;
      this.animate(o,o.ary[c],sz*(o.ud>0?1:-1),0,d,o.ms);
      this.animate(o,o.ary[o.cnt],0,sz*(o.ud>0?-1:1),d,o.ms,true);
      o.cls&&o.ct?o.ct.className='':null;
      o.ct=o.cls&&o.thumbs[c]?o.thumbs[c]:null;
      o.cls&&o.ct?o.ct.className=o.cls:null;
      o.cnt=c;
     },
    
     animate:function(o,a,f,t,srt,mS,ud){
      clearTimeout(a[4]);
      var oop=this,ms=new Date().getTime()-srt,n=(t-f)/mS*ms+f;
      if (isFinite(n)){
       a[0].style[a[1]]=n+'px';
       a[2]=n;
      }
      if (ms<mS){
       a[4]=setTimeout(function(){ oop.animate(o,a,f,t,srt,mS,ud); },10);
      }
      else {
       a[0].style[a[1]]=(ud?3000:t)+'px';
       o.auto&&ud?oop.Auto(o.id,o.hold):null;
      }
     },
    
     mse:function(id,obj,e){
      var o=this['zxc'+id];
      if (o&&obj!=o.ct&&o.cls){
       obj.className=e.type=='mouseout'?'':'onClick';
      }
     },
    
     addevt:function(o,t,f,p,p1){
      var oop=this;
      if (o.addEventListener){
       o.addEventListener(t,function(e){ return oop[f](p,p1,e);}, false);
      }
      else if (o.attachEvent){
       o.attachEvent('on'+t,function(e){ return oop[f](p,p1,e); });
      }
     }
    
    
    
    }
    
    
    zxcSlider.init({
     SliderID:'preview_outer', // the unique ID name of the slider parent DIV.                           (string)
     ThumbsID:'thumbs',        // the unique ID name of the thumbnals parent DIV.                        (string)
     ThumbsClass:'onClick',    //(optional) the class name of the active and mouseover thumbnails.       (string, default = no class name change)
     Animate:1000,             //(optional) the animation duration in milli seconds.                     (number, default = 1000)
     Hold:2000,                //(optional) the auto rotation 'hold' delay milli seconds.                (number, default = Animate*4)
     Direction:1,              //(optional) the auto rotate direction, > 0 = anticlock, < 0 = clockwise. (number, default = > 0 = clockwise)
     AutoStart:5000,           //(optional) the delay milli seconds before starting auto rotate.         (number, default = no auto start)
     AddEvents:[               //(optional) an array defining event calls to add.                        (array, default = in line event calls)
     // field 0 = the unique ID name of the element.
     // field 1 = the event type.
     // field 0 = the script function name.
     // field 0 = the parameter to pass to the function.
    
     ['buttonLeft','mouseup','Next',1],
     ['buttonRight','mouseup','Next',-1],
     ['preview_wrap','mouseover','Pause'],
     ['preview_wrap','mouseout','Auto']
     ]
    
    });
    Vic

    God loves you and will never love you less.

    http://www.vicsjavascripts.org/Home.htm
    If my post has been useful please donate to http://www.operationsmile.org.uk/

  5. #5
    Join Date
    Jun 2013
    Posts
    3
    Wow Vic, that is exactly what I needed. Thank you so much.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center

"

"

X vBulletin 4.2.2 Debug Information

  • Page Generation 0.09519 seconds
  • Memory Usage 3,034KB
  • Queries Executed 13 (?)
More Information
Template Usage (31):
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_global_above_footer
  • (1)ad_global_below_navbar
  • (1)ad_global_header1
  • (1)ad_global_header2
  • (1)ad_navbar_below
  • (2)bbcode_code
  • (1)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)headinclude_bottom
  • (5)memberaction_dropdown
  • (1)navbar
  • (4)navbar_link
  • (1)navbar_moderation
  • (1)navbar_noticebit
  • (1)navbar_tabs
  • (2)option
  • (5)postbit
  • (5)postbit_onlinestatus
  • (5)postbit_wrapper
  • (1)showthread_list
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available (6):
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files (27):
  • ./showthread.php
  • ./global.php
  • ./includes/class_bootstrap.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/functions_navigation.php
  • ./includes/class_friendly_url.php
  • ./includes/class_hook.php
  • ./includes/class_bootstrap_framework.php
  • ./vb/vb.php
  • ./vb/phrase.php
  • ./includes/functions_facebook.php
  • ./includes/functions_calendar.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_notice.php
  • ./includes/functions_threadedmode.php
  • ./packages/vbattach/attach.php
  • ./vb/types.php
  • ./vb/cache.php
  • ./vb/cache/db.php
  • ./vb/cache/observer/db.php
  • ./vb/cache/observer.php 

Hooks Called (71):
  • init_startup
  • friendlyurl_resolve_class
  • init_startup_session_setup_start
  • database_pre_fetch_array
  • database_post_fetch_array
  • init_startup_session_setup_complete
  • global_bootstrap_init_start
  • global_bootstrap_init_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • load_show_variables
  • load_forum_show_variables
  • global_state_check
  • global_bootstrap_complete
  • global_start
  • style_fetch
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • strip_bbcode
  • friendlyurl_clean_fragment
  • friendlyurl_geturl
  • forumjump
  • cache_templates
  • cache_templates_process
  • template_register_var
  • template_render_output
  • fetch_template_start
  • fetch_template_complete
  • parse_templates
  • fetch_musername
  • notices_check_start
  • notices_noticebit
  • process_templates_complete
  • friendlyurl_redirect_canonical
  • showthread_post_start
  • showthread_query_postids_threaded
  • showthread_threaded_construct_link
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • memberaction_dropdown
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • build_navigation_data
  • build_navigation_array
  • check_navigation_permission
  • process_navigation_links_start
  • process_navigation_links_complete
  • set_navigation_menu_element
  • build_navigation_menudata
  • build_navigation_listdata
  • build_navigation_list
  • set_navigation_tab_main
  • set_navigation_tab_fallback
  • navigation_tab_complete
  • fb_like_button
  • showthread_complete
  • page_templates