1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Help with an interactive slideshow

Discussion in 'jQuery' started by supercain, Dec 19, 2013.

  1. #1
    Hi,

    i made an interactive slideshow with the help of other users here that allows you to slide the current image and another user on their own end can see the changes in real time. The page kinda works its just that it gets stuck after a while. I use jquery to have the page continuously read a value stored in an external txt file which contains the ID of the current image so it can detect when it changes and slide to that image. However seems like this method overloads the page and thats what makes it get stuck.

    This is my code as of now:

    (function(d) {
        var get = ajaxNew(function() {
            if ((this.readyState == 4) && (!get.ignore)) {
                var id = 'visual' + get.responseText;
                if (
                    (this.status == 200) &&
                    (current.id != id)
                ) setCurrent(d.getElementById(id));
                this.nextEvent = setTimeout(request, 1000);
            }
        });
       
        if (get !== false) {
            var
                t,
                fader = d.getElementById('fader'),
                botones = d.getElementById('botones'),
                divstatus = d.getElementById('status'),
                tags = fader.querySelectorAll('img, iframe'),
                iList = tags,
                iListMax = iList.length - 1,
                set = ajaxNew(function() {
                    if (this.readyState == 4) {
                        textReplace(status, current.id);
                        get.ignore = false;
                        get.nextEvent = setTimeout(request, 1000);
                    }
                }),
                current = iList[0],
                status = d.createElement('div'),
                previous = false;
               
            function prevent(e) {
                if (e.preventDefault) e.preventDefault();
                e.returnValue = false;
            }
    
            function setCurrent(e) {
                if (current != e) {
                    get.ignore = true;
                    clearTimeout(get.nextEvent);
                    if (previous) classRemove(previous, 'previous');
                    if (current) {
                        classSwap(current, 'current', 'previous');
                        previous = current;
                    }
                    current = e;
                    classAdd(e, 'current');
                    set.open('GET', 'imageId.txt', true);
                    set.send();
                }
                    var isJPG = $(current).attr('src').split('.').pop();
        if($('#fader').hasClass('scriptedFader') && isJPG == 'JPG') {
          classSwap(fader, 'scriptedFader', 'visorclose');
        } else if($('#fader').hasClass('visorclose') && isJPG != 'JPG') {
          classSwap(fader, 'visorclose', 'scriptedFader');
        }
            }
               
            classAdd(fader,'visorclose');
        
            function request() {
                get.open('GET','imageId.txt', true);
                get.send();
                this.ignore = false;
            }
        
            request();
           
            divstatus.appendChild(status);
           
        } // might want to add an else handler for no AJAX here
    })(document);
    Code (markup):
    The html code is really simple, only the images on the gallery:

    <img id="visual1" src="01.jpg">
    <img id="visual2" src="02.jpg">
    
    and so on
    HTML:
    Also 2 buttons, one for going to the next image and other for the previous. They only thing they do is to update the value in the text file with the current one. They work fine so no need to put here.

    I would like to know if there is a more effective alternative for this. Something like the way Facebook and google notifies you of new messages without having to reload the page.

    Thank you.
     
    supercain, Dec 19, 2013 IP
  2. supercain

    supercain Greenhorn

    Messages:
    29
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    21
    #2
    Hello? Any help please?
     
    supercain, Dec 21, 2013 IP
  3. HuggyStudios

    HuggyStudios Well-Known Member

    Messages:
    724
    Likes Received:
    20
    Best Answers:
    26
    Trophy Points:
    165
    #3
    HuggyStudios, Dec 22, 2013 IP
  4. supercain

    supercain Greenhorn

    Messages:
    29
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    21
    #4
    The text file only contains a number: 1, 2 or whatever the image ID is supposed to be. I do it like this because both users are supposed to see the changes simultaneously on their own ends. For example, if user 1 press the button NEXT, he sees the images slide to the next one and user 2 sees it too without moving a finger.
     
    supercain, Dec 22, 2013 IP
  5. supercain

    supercain Greenhorn

    Messages:
    29
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    21
    #5
    Hello?? What about some help? Please?
     
    supercain, Dec 28, 2013 IP
  6. HuggyStudios

    HuggyStudios Well-Known Member

    Messages:
    724
    Likes Received:
    20
    Best Answers:
    26
    Trophy Points:
    165
    #6
    I think the obvious points are that you aren't using jQuery throughout your script. Try and incorporate all of jQuery's functionality (they take care of cross browser performance issues).
     
    HuggyStudios, Dec 28, 2013 IP
  7. supercain

    supercain Greenhorn

    Messages:
    29
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    21
    #7
    What you mean im not using jquery? Could you please give me a acmore concrete answer?
     
    supercain, Dec 28, 2013 IP
  8. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,998
    Best Answers:
    253
    Trophy Points:
    515
    #8
    It needs to be accessed by multiple users so if one user changes it, everyone sees it. Localstorage can't do that at ALL.

    As I told you SEVERAL times when I gave you that original code, it doesn't use jQuery, it's just flat javascript because it was less code, less effort, and less problems without getting the steaming train wreck of asshattery known as jQuery involved.

    You've gone and mixed the idiotic halfwit bull known as jQuery into it, and that's why it doesn't work right anymore! Generally speaking how I write scripting and what jQuery does are NOT compatible -- in fact they tend to get along like sodium and water.
     
    deathshadow, Dec 30, 2013 IP
  9. supercain

    supercain Greenhorn

    Messages:
    29
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    21
    #9
    Well man... to be honest, it never worked quite right and i told you that many times too. With your code the current image keeps jumping back to the previous one all the time. With my modifications i dont have this problem anymore and it works quite fine mostly but it still doesnt work as good as i need because it gets stuck from time to time. It only happens when i have loaded more than 50 images or so.

    Anyway, if somebody else can provide really helpful answers instead of insults i will appreciate it.
     
    supercain, Dec 30, 2013 IP
  10. supercain

    supercain Greenhorn

    Messages:
    29
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    21
    #10
    Nobody willing to help?
     
    supercain, Jan 17, 2014 IP
  11. HuggyStudios

    HuggyStudios Well-Known Member

    Messages:
    724
    Likes Received:
    20
    Best Answers:
    26
    Trophy Points:
    165
    #11
    I'm not sure why your problem but it could be related to the image being stored in the browser's memory?
     
    HuggyStudios, Jan 18, 2014 IP
  12. supercain

    supercain Greenhorn

    Messages:
    29
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    21
    #12
    You mean there are too many images and thats why the browser gets stuck?
     
    supercain, Jan 18, 2014 IP
  13. HuggyStudios

    HuggyStudios Well-Known Member

    Messages:
    724
    Likes Received:
    20
    Best Answers:
    26
    Trophy Points:
    165
    #13
    It could be that. I'm just guessing without looking at the network in my developer tools. Try removing old images from the browser and see if that improves things.
     
    HuggyStudios, Jan 19, 2014 IP
  14. supercain

    supercain Greenhorn

    Messages:
    29
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    21
    #14
    Hi,

    i think there is a problem with the code itself because the page gets stuck on both sides. Did you see the code i posted? What do you think?
     
    supercain, Jan 19, 2014 IP