Forums

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

Home Forums JavaScript trying to create an elevator simulation but timing won't work

  • This topic is empty.
Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #168986
    fredtbx
    Participant
    var current_floor = 1;
    floor_stops = ["400", "300", "250"];
    $( "#start_btn" ).click(function() {
        //$( "#left_door" ).animate({ width: "10%" }, 2000); 
        //          $( "#left_door" ).animate({ width: "100%" }, 3000).delay(5000);
        while (floor_stops.length > 0) {
            if (current_floor != floor_stops[0]) {
                curr_floor = current_floor + 1;
                $( "#left_door" ).animate({ "width": "10%" }, 2000) 
                    .animate({ "width": "100%" }, 3000, function(){ 
                        $( "#elevator" ).animate({ "top": (floor_stops[0])+"px" }, 5000)
                    });                                                     
                floor_stops.shift();
            } else {
                curr_floor = current_floor + 1;
            }
        }           
    });
    
    #168987
    fredtbx
    Participant

    Here is a fiddle for an attempt…

    http://jsfiddle.net/Nr5G5/1/

    #168991
    Paulie_D
    Member

    Perhaps you could explain exactly how it’s supposed to look and operate because it’s not clear to me.

    #168992
    fredtbx
    Participant

    Hi Paulie,

    The div height is 50, I want it to start at top: 500 and make it go up 50px to top:450, stop, open and close the doors and go up another 50px to top:400, stop, open the doors etc.

    #168993
    fredtbx
    Participant

    I’ve been struggling for a few days with this. To learn how to do this correctly will greatly add to my JS toolkit.

    #169000
    fredtbx
    Participant

    Hi nkrsic, it’s in the CSS section in the elevator div.

    #169002
    fredtbx
    Participant

    I’ve updated the fiddle to run like I need it to run http://jsfiddle.net/Nr5G5/3/,
    but it’s in long hand, now I need to make it dynamic, in a loop, like the first fiddle and have the #elevators top property change using the floor_stops array.

    #169010
    fredtbx
    Participant

    Right nkrisc, that was somebodys edit from Stack Overflow that I put in there. My original is in this latest fiddle, http://jsfiddle.net/Nr5G5/5/. I’m using an array to change the top value in line 11.
    In the first fiddle, they said to // Create an IIFE to capture the value, between lines 8 and 9, which I think would have supplied top. I’m new to IIFE’s.

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