11/*
22Welcome to the 60fps project! Your goal is to make Cam's Pizzeria website run
33jank-free at 60 frames per second.
4-
54There are two major issues in this code that lead to sub-60fps performance. Can
65you spot and fix both?
7-
8-
96Built into the code, you'll find a few instances of the User Timing API
107(window.performance), which will be console.log()ing frame rate data into the
118browser console. To learn more about User Timing API, check out:
129http://www.html5rocks.com/en/tutorials/webperformance/usertiming/
13-
1410Creator:
1511Cameron Pittman, Udacity Course Developer
1612cameron *at* udacity *dot* com
@@ -492,7 +488,7 @@ function updatePositions() {
492488 var items = document . getElementsByClassName ( 'mover' ) ; //? where is .mover defined? ln 529
493489 var phaseBase = document . body . scrollTop / 1250 ;
494490 for ( var i = 0 ; i < items . length ; i ++ ) {
495- var phase = Math . sin ( phaseBase + ( i % 8 ) ) * 100 + "px" ;
491+ var phase = Math . sin ( phaseBase + ( i % 8 ) ) * 200 + "px" ;
496492 items [ i ] . style . transform = "translate3d(" + phase + ",0,0)" ; //used to be items[i].style.left = ...
497493 }
498494
@@ -517,13 +513,15 @@ document.addEventListener('DOMContentLoaded', function() {
517513 var colNum = 8 ;
518514 var rowNum = 5 ;
519515 var rowHeight = Math . floor ( window . innerHeight / rowNum ) ;
516+ var colWidth = Math . floor ( window . innerWidth / colNum ) ;
520517 var pizzaNum = colNum * rowNum ;
521518 var movingPizzas = document . getElementById ( "movingPizzas1" ) ;
522519 for ( var i = 0 ; i < pizzaNum ; i ++ ) {
523520 var elem = document . createElement ( 'img' ) ;
524521 elem . className = 'mover' ;
525522 elem . src = "images/pizza.png" ;
526523 elem . style . top = ( Math . floor ( i / colNum ) * rowHeight ) + 'px' ;
524+ elem . basicLeft = ( i % colNum ) * colWidth ;
527525 movingPizzas . appendChild ( elem ) ;
528526 }
529- } ) ;
527+ } ) ;
0 commit comments