JavaScript/JQuery help

Discussion in 'Software' started by llama91, Mar 5, 2012.

  1. llama91

    llama91 Private E-2

    Greetings all you helpful people,
    I'm having a little issue with JQuery I was hoping you could either help me with or around.

    On the page i have 3 div's
    bg1
    bg2
    bg3

    positioned absolute, and on top of each other. With bg3 at the top and bg1 at the bottom.
    This was intended to create a transitional image change effect in which i use jquery to fade out the top two images one by one, and then fade them back in.

    So the code I have currently is:

    var direction = 0; // This is the direction of the fading in or fading out
    var current = 3; // this keeps track of which current div is visable

    function imgTimer()
    {
    if (current == 3){
    direction = 0; // if current is 3, the top div, then the direction is 0 or down
    }
    else if (current == 1){
    direction = 1; // if current is 1, the botom div, then the direction is 1 or up
    }

    if (direction == 0){
    var iddown = "#bg"+current; //if the direction is down, fade out the current bg
    $(iddown).fadeout("0.5"); //problem occurs here
    current = current - 1; //set current to the one lower
    }else if(direction == 1){
    current = current + 1; // if the direction is up, set current to the div above;
    idup = "#bg"+current; // fade in the bg div above
    $(idup).fadein("0.5"); // problem here also
    }
    t=setTimeout("imgTimer()",8000); //recalls function after 8 seconds, with any luck
    }


    The problem occurs on these two lines:
    $(iddown).fadeout("0.5");
    $(idup).fadein("0.5");


    I have tried to implement a variable for what should be:
    "#bg3"
    or any of the other 2.
    unfortunately when the script runs it cannot process the variable as a function parameter.

    Firefox gives the error:
    Error: $(iddown).fadeout is not a function
    Source File: http://localhost/script.js
    Line: 107


    Is there any way I can make this pass as a string? or a different way I could work around this.
    The fading effect is kind of necessary, because I'm not looking for a solid change.
    I may have either over complicated this method or preformed some kind of bad code practice, so any and all input is welcome.

    Regards,
    Llama91
     
  2. llama91

    llama91 Private E-2

    Well I found out what was wrong

    > $(iddown).fadeout
    >> $(iddown).fadeOut


    Yup, I left out a cap in the function ¬_¬,
    for those reading this in search of answers to their own issues

    $("#bg" + current).fadeOut(2000);
    This is also acceptable, and parses properly.

    Apologies for the thread ^^
     

MajorGeeks.Com Menu

Downloads All In One Tweaks \ Android \ Anti-Malware \ Anti-Virus \ Appearance \ Backup \ Browsers \ CD\DVD\Blu-Ray \ Covert Ops \ Drive Utilities \ Drivers \ Graphics \ Internet Tools \ Multimedia \ Networking \ Office Tools \ PC Games \ System Tools \ Mac/Apple/Ipad Downloads

Other News: Top Downloads \ News (Tech) \ Off Base (Other Websites News) \ Way Off Base (Offbeat Stories and Pics)

Social: Facebook \ YouTube \ Twitter \ Tumblr \ Pintrest \ RSS Feeds