Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript Javascript question

  • This topic is empty.
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #40835
    inkblot
    Member

    Hello Everybody,
    I’m a web designer from chicago.
    I’m working on some javascript code. It’s jquery for a custom photo rotater that I created. It works right now but I’m looking to optimize it.

    What do you guys think? Anything I can do to clean it up?

    // JavaScript Document

    //global parameters for controlling the sliding.

    function slider(numpics, imgwidth, mydiv){
    this.mypos = mydiv;
    this.newpos = 0;
    this.imgwidth = 0;
    this.myarray = new Array;
    this.mycounter = 0;
    this.total = 0;
    this.curpos = 0;
    this.times;

    this.intialize = intialize;
    this.moveNext = moveNext;
    this.movePrev = movePrev;
    }

    /*this function intializes the postions for sliding. It has to be called on the page to make the sliding work.
    numpics = number of divisons to slide through,
    imgwidth = the width of the container,
    mydiv = name of div that slides
    */
    function intialize(numpics, imgwidth, mydiv){
    while(this.mycounter < numpics){
    this.myarray[this.mycounter] = (imgwidth*this.mycounter)*-1;
    this.mycounter ++;
    }
    this.total = numpics – 1;
    this.mypos = mydiv;

    }

    /*this function controls forward sliding*/
    function moveNext(){
    if(this.newpos < this.total)
    {this.newpos += 1;}
    else
    {this.newpos =0; }
    this.curpos = this.myarray[this.newpos];
    $(this.mypos).stop().animate({
    left:this.curpos
    }, 800, function (){});

    }

    /*this function controls backward sliding*/
    function movePrev(){
    if(this.newpos > 0)
    {this.newpos -= 1;}
    else
    {this.newpos = this.total; }
    this.curpos = this.myarray[this.newpos];
    $(this.mypos).stop().animate({
    left:this.curpos
    }, 800, function (){});
    }

    #114595
    JohnMotylJr
    Participant

    @inkblot,
    Only thing i would add, have you ran timing tests for your functions?

    this.myarray = [];
    #114737
    inkblot
    Member

    @JohnMotylJr no I had not done that.
    I’ll give it a shot.

    Thanks for the suggestion.

Viewing 3 posts - 1 through 3 (of 3 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.