SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Enthusiast
    Join Date
    Feb 2010
    Posts
    99
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Problem with fader/fadeshow (preloading)

    Hi

    I've got this fadeshow and I'm trying to delay starting time of it.

    http://web.zone.ee/testcss/

    I added this code to the script, to the very end of the script specifically to this "fadeshow.prototype.startit=function(){" :
    Code:
    if (loaded) { 
    alert("OK")
    this.populateslide(crossobj, this.curimageindex)
    }
    So the script will be populated with the images when they are loaded,
    it seems to delay the loading of the slideshow, for some 4 seconds.
    But I can't figure it out, when I set the speed of the download to lower, it still starts after some time, but not with pictures loaded, but still loading.
    That shows me it isn't working, but why the delay then? And why isn't it showing the alert message?
    I've tried with setTimeout, but it doesn't seem to even consider the milliseconds I feed it. Sometimes it gives me crossobj isn't defined

  2. #2
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I tried to look a bit deeper, but that script is really a mess - no formatting, missing braces etc...

    Anyway, you need to do whatever it is you do to initialize the script, only after the images have loaded. It looks like you kinda intended to do that in your startit() method when you check for the loaded boolean variable, but, you only call startit() once, and since you call the method right away, it's pretty much guaranteed that loaded is false, making it useless.

    Maybe your function where you set the loaded variable to true, would be better if you just got rid of the boolean variable altogether, and just "started the slideshow" right then and there.

    I still think it would have been easier to do this logic outside of that script, and just modify the script to not use document.write.

  3. #3
    SitePoint Enthusiast
    Join Date
    Feb 2010
    Posts
    99
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I tried adding that code to the countLoadedImages
    Code JavaScript:
    fadeshow.prototype.startit

    It doesn't work, even if I call new fadeshow from console, it doesn't display anything. I think it's the order of commands what is the problem here.

    The code is a mess, I tried to reformat it, but somewhere in the middle of it I gave up.

    I haven't found a better slider either, I have but, their overall size (with frameworks) is much larger then needed.
    I guess it's unrational fear, since the frameworks could be already downloaded.

  4. #4
    SitePoint Enthusiast
    Join Date
    Feb 2010
    Posts
    99
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I've been coding and I changed write method to innerHTML.
    It seems to be working now.

    Now I'm trying to do the same thing with nivo slider.
    http://web.zone.ee/testcss/nivo/
    It seems not to take array of javascript img objects but img tags.

    Added this loop, it is supposed to add image elements to the slider div.
    Somewhy it doesn't do that, I'm not really familiar with JQuery, but this seems straightforward enough.
    Code JavaScript:
    for (var i = 0, len = fadeimagesPHP.length; i < len; i++) {
    alert("OK");
    $('#slider').append('<img src="'fadeimagesPHP[i][0]'" width="798" height="358" alt="" />');
    }
    }

    It seems the problem has to do with JQuery line, when I remove it the loop starts working

  5. #5
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You need to use the + operator to concatenate strings.

  6. #6
    SitePoint Enthusiast
    Join Date
    Feb 2010
    Posts
    99
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No change, no elements get added.


Bookmarks

Posting Permissions

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