Skip to content

Commit

Permalink
Feat: Optimization project for Udacity nanodegree
Browse files Browse the repository at this point in the history
  • Loading branch information
D-Pankey committed Aug 10, 2017
1 parent 7221a60 commit bfcb0f4
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 34 deletions.
7 changes: 4 additions & 3 deletions css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ html {
-ms-text-size-adjust: 100%;
-webkit-text-size-adjust: none;
}
body { margin: 0; font-size: 14px; line-height: 1.61; font-weight: 400; }
body, button, input, select, textarea { font-family: 'Open Sans', sans-serif; color: #333; }
/*body { margin: 0; font-size: 14px; line-height: 1.61; font-weight: 400; }
body, button, input, select, textarea { font-family: 'Open Sans', sans-serif; color: #333; }*/

a { color: #12C; }
a:visited { color: #61C; }
Expand Down Expand Up @@ -43,7 +43,8 @@ footer {
footer span { float: right; font-style: italic; }

/* Smartphones (portrait) */
@media only screen and (max-width: 480px) {
@media only screen and (max-width: 480px)
{
body { font-size: 12px;}
header p { padding-left: 4.5em;}
}
15 changes: 9 additions & 6 deletions index.html
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
<!DOCTYPE html>
<html lang="en">
<head>
<style>
b,header p,strong{font-weight:700}.hero,footer{border-top:1px solid #ccc}footer span,li p{font-style:italic}html{font-size:100%;overflow-y:scroll;-webkit-tap-highlight-color:transparent;-ms-text-size-adjust:100%;-webkit-text-size-adjust:none}a{color:#12C}a:visited{color:#61C}a:focus{outline:dotted thin}a:active,a:hover{color:#c00;outline:0}code,pre{font-family:monospace,monospace;font-size:1em}ol,ul{margin:1em 0;padding:0 0 0 20px}img{border:0;max-width:100%}body{background:#fff}.container,footer,header{max-width:45em;margin:0 auto}header{padding:0 .5em;color:#C90B0B}header img{border-radius:40px;float:left}header p{font-size:1.5em;padding-left:4em}header p span{font-size:.8em;font-weight:400}.hero{padding:2em;background-color:#f8f8f8;font-size:1.2em;border-bottom:1px solid #ccc}.content{padding:1em}.content li{list-style-type:none;font-size:1.1em}li img{float:left;padding-right:1em}li p{font-size:.9em}footer{padding:0 .5em}footer span{float:right}/*@media only screen and (max-width:480px){body{font-size:12px}header p{padding-left:4.5em}}*/
</style>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content=" FILL ME IN ">
<meta name="author" content=" FILL ME IN ">
<title>Cameron Pittman: Portfolio</title>

<!-- Hmm, what is the impact of web fonts on speed? Measure it... -->
<link href="//fonts.googleapis.com/css?family=Open+Sans:400,700" rel="stylesheet">
<!-- <link href="//fonts.googleapis.com/css?family=Open+Sans:400,700" rel="stylesheet"> -->

<link href="css/style.css" rel="stylesheet">
<link href="css/print.css" rel="stylesheet">
<!-- <link href="css/style.css" rel="stylesheet"> -->
<link href="css/print.css" rel="stylesheet" media="print">

<script>
(function(w,g){w['GoogleAnalyticsObject']=g;
Expand All @@ -21,13 +24,13 @@
ga('create', 'UA-XXXX-Y');
ga('send', 'pageview');
</script>
<script src="http://www.google-analytics.com/analytics.js"></script>
<!-- <script src="http://www.google-analytics.com/analytics.js"></script> -->
<script async src="js/perfmatters.js"></script>
</head>

<body>
<header>
<a href="/"><img src="img/profilepic.jpg"></a>
<a href="/"><img src="img/newprofilepic.jpg"></a>
<p>Cameron Pittman<br><span>Course Developer</span></p>
</header>

Expand Down Expand Up @@ -57,7 +60,7 @@
</li>

<li>
<img style="width: 100px;" src="views/images/pizzeria.jpg">
<img style="width: 100px;" src="views/images/pizzeriamin.jpg">
<a href="views/pizza.html">Cam's Pizzeria</a>
<p>Who wants a performant pizza?</p>
</li>
Expand Down
Binary file modified views/images/pizzeria.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
70 changes: 45 additions & 25 deletions views/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -418,43 +418,51 @@ var resizePizzas = function(size) {
console.log("bug in changeSliderLabel");
}
}


changeSliderLabel(size);

// Returns the size difference to change a pizza element from one size to another. Called by changePizzaSlices(size).
function determineDx (elem, size) {
var oldWidth = elem.offsetWidth;
var windowWidth = document.querySelector("#randomPizzas").offsetWidth;
var oldSize = oldWidth / windowWidth;
// // Returns the size difference to change a pizza element from one size to another. Called by changePizzaSlices(size).
// function determineDx (elem, size) {
// var oldWidth = elem.offsetWidth;
// var windowWidth = document.querySelector("#randomPizzas").offsetWidth;
// var oldSize = oldWidth / windowWidth;

// Changes the slider value to a percent width
function sizeSwitcher (size) {
// // Changes the slider value to a percent width
// function sizeSwitcher (size) {

// Iterates through pizza elements on the page and changes their widths
function changePizzaSizes(size) {
switch(size) {
case "1":
return 0.25;
newwidth = 25;
break;
case "2":
return 0.3333;
newwidth = 33.3;
break;
case "3":
return 0.5;
newwidth = 45;
break;
default:
console.log("bug in sizeSwitcher");
}
}
// puts the collection of document.querySelectorAll to variable
var randomPizzas = document.querySelectorAll(".randomPizzaContainer");

for (var i = 0; i < randomPizzas.length; i++) {
// this should not be in for loop it was showing up in timeline that is was running over and over
// var dx = determineDx(randomPizzas[i], size);
randomPizzas[i].style.width = newwidth +"%";/*sets the width for every element to the percentage*/

var newSize = sizeSwitcher(size);
var dx = (newSize - oldSize) * windowWidth;
}

return dx;
}
}


// Iterates through pizza elements on the page and changes their widths
function changePizzaSizes(size) {
for (var i = 0; i < document.querySelectorAll(".randomPizzaContainer").length; i++) {
var dx = determineDx(document.querySelectorAll(".randomPizzaContainer")[i], size);
var newwidth = (document.querySelectorAll(".randomPizzaContainer")[i].offsetWidth + dx) + 'px';
document.querySelectorAll(".randomPizzaContainer")[i].style.width = newwidth;
}
}





changePizzaSizes(size);

Expand Down Expand Up @@ -497,16 +505,28 @@ function logAverageFrame(times) { // times is the array of User Timing measure
// https://www.igvita.com/slides/2012/devtools-tips-and-tricks/jank-demo.html

// Moves the sliding background pizzas based on scroll position
//Reads variables first instead of inside loop,


function updatePositions() {
frame++;
window.performance.mark("mark_start_frame");

var items = document.querySelectorAll('.mover');
var scroll =document.body.scrollTop / 1250;
var items = document.querySelectorAll('.mover');
for (var i = 0; i < items.length; i++) {
var phase = Math.sin((document.body.scrollTop / 1250) + (i % 5));
var phase = Math.sin (scroll + (i % 5));
items[i].style.left = items[i].basicLeft + 100 * phase + 'px';
}

/* this was causing forced sync.layout
var items = document.querySelectorAll('.mover');
for (var i = 0; i < items.length; i++) {
var phase = Math.sin((document.body.scrollTop / 1250) + (i % 5));
items[i].style.left = items[i].basicLeft + 100 * phase + 'px';
}
*/
// User Timing API to the rescue again. Seriously, it's worth learning.
// Super easy to create custom metrics.
window.performance.mark("mark_end_frame");
Expand Down

0 comments on commit bfcb0f4

Please sign in to comment.