Home › Forums › JavaScript › trying to create an elevator simulation but timing won't work
- This topic is empty.
-
AuthorPosts
-
May 1, 2014 at 9:49 am #168986
fredtbx
Participantvar 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; } } });
May 1, 2014 at 9:56 am #168987fredtbx
ParticipantHere is a fiddle for an attempt…
May 1, 2014 at 10:17 am #168991Paulie_D
MemberPerhaps you could explain exactly how it’s supposed to look and operate because it’s not clear to me.
May 1, 2014 at 10:21 am #168992fredtbx
ParticipantHi 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.
May 1, 2014 at 10:23 am #168993fredtbx
ParticipantI’ve been struggling for a few days with this. To learn how to do this correctly will greatly add to my JS toolkit.
May 1, 2014 at 12:52 pm #169000fredtbx
ParticipantHi nkrsic, it’s in the CSS section in the elevator div.
May 1, 2014 at 1:53 pm #169002fredtbx
ParticipantI’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.May 1, 2014 at 3:42 pm #169010fredtbx
ParticipantRight 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. -
AuthorPosts
- The forum ‘JavaScript’ is closed to new topics and replies.