3030
3131const imgCat = document . getElementsByTagName ( 'img' ) [ 0 ] ;
3232imgCat . style . left = '0px' ;
33- let halfWin = window . innerWidth - imgCat . width ;
33+ let speed = 1 ;
34+ let time ;
35+ let winScreen = window . innerWidth - imgCat . width ;
3436function catWalk ( ) {
3537 const currentLeft = parseInt ( imgCat . style . left ) ;
36- imgCat . style . left = ( currentLeft + 10 ) + 'px' ;
38+
39+ imgCat . style . left = ( currentLeft + speed ) + 'px' ;
40+
3741
3842 // const time = Date.now()
3943 // const time2 = time + 5000
4044 // console.log(time)
4145
42- let timeObject = new Date ( ) ;
43- let milliseconds = 10 * 1000 ; // 10 seconds = 10000 milliseconds
44- timeObject = new Date ( timeObject . getTime ( ) + milliseconds ) ;
45- console . log ( timeObject )
46+ // let timeObject = new Date();
47+ // let milliseconds= 10 * 1000; // 10 seconds = 10000 milliseconds
48+ // timeObject = new Date(timeObject.getTime() + milliseconds);
49+ // console.log(timeObject)
4650
47- // const time = new Date()
48- // time.setSeconds(time.getSeconds() + 5);
49- // console.log(time)
51+
52+
53+ if ( currentLeft == winScreen / 2 ) {
54+ speed = 0 ;
55+ time = new Date ( )
56+ time . setSeconds ( time . getSeconds ( ) + 5 ) ;
5057
51- if ( currentLeft == ( halfWin ) / 2 ) {
5258 imgCat . src = 'https://media.giphy.com/media/Qd8Fwmm0PgTcc/giphy.gif' ;
53-
54-
55- } else if ( time2 > 5000 ) {
56- imgCat . src = 'http://www.anniemation.com/clip_art/images/cat-walk.gif' ;
59+ let now = new Date ( ) ;
60+ while ( now . getTime ( ) - time . getTime ( ) < 2000 ) {
61+ now = new Date ( ) ;
62+ }
5763
58- } else if ( currentLeft > ( halfWin ) ) {
5964
60- imgCat . style . left = '0px' ;
61- }
65+ } else if ( currentLeft > ( winScreen ) ) {
66+
67+ imgCat . style . left = '0px' ;
68+ }
6269
6370
6471
6572}
6673
6774
68- // setInterval(catWalk, 50 );
75+ // setInterval(catWalk, 1 );
0 commit comments