-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Commit for class 3 up to exercise 3. Events, clicks, mouseovers, etc.
- Loading branch information
1 parent
c67bf6f
commit f0451bc
Showing
4 changed files
with
215 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<html> | ||
<head> | ||
<title>My Site!</title> | ||
<link rel="stylesheet" href="style.css"> | ||
<script src = "http://code.jquery.com/jquery-1.8.3.min.js"></script> | ||
<script src = "javascript.js"></script> | ||
</head> | ||
<body> | ||
My Site!</br> | ||
<a href = "#" id = "calculate">Calculate life time supply</a><br/> | ||
<div id = "lifetime-supply"> | ||
|
||
</div> | ||
<a href = "#" id = "favorites">See my favorite things</a> | ||
<div id = "favorite-things"> | ||
|
||
</div> | ||
<a href = "#" id = "friends">My friends</a> | ||
<div class = "box"> | ||
</div> | ||
<div class = "box"> | ||
</div> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
$(document).ready(function(){ | ||
$('.box').bind({ | ||
click: function() { | ||
$(this).css('background-color', 'green') | ||
$(this).html('Clicked!') | ||
}, | ||
mouseenter: function() { | ||
$(this).css('background-color', 'purple') | ||
$(this).html('Hi!') | ||
}, | ||
mouseleave: function(){ | ||
$(this).css('background-color', 'orange') | ||
$(this).html('Bye!') | ||
} | ||
}); | ||
$('#calculate').click(calculate); | ||
$('#favorites').click(favoriteThings); | ||
$('#friends').click(myFriends); | ||
}) | ||
|
||
function calculate(){ | ||
var age = 26; | ||
var oldAge = 96; | ||
var perDay = 2; | ||
|
||
var days = (oldAge - age) * 356; | ||
var total = perDay * days; | ||
var resultDiv = $('#lifetime-supply') | ||
if(total > 40000){ | ||
resultDiv.html("You will need " + total + " to last you until the ripe old age of " + oldAge + ". Wow! That's a lot!"); | ||
}else{ | ||
resultDiv.html("You will need " + total + " to last you until the ripe old age of " + oldAge + ". You seem pretty reasonable"); | ||
} | ||
} | ||
|
||
function favoriteThings(){ | ||
var favoriteThings = ['Rabbits', 'Orange', 'Yogurt', 'Brussel Sprouts', 'Otters']; | ||
var resultDiv = $('#favorite-things'); | ||
|
||
var resultParagraph = $('<p></p>'); | ||
var result = 'My favorite things are: '; | ||
|
||
for (var i = 0; i<favoriteThings.length; i++){ | ||
if (i < favoriteThings.length - 1){ | ||
result += favoriteThings[i] + ', '; | ||
}else{ | ||
result += "and " + favoriteThings[i] + '.'; | ||
} | ||
} | ||
resultParagraph.append(result); | ||
resultDiv.append(resultParagraph); | ||
} | ||
function myFriends(){ | ||
var friends = [ | ||
{name: 'Santa Claus', | ||
hair: 'red'}, | ||
{name: 'Easter Bunny', | ||
hair: 'brown'}, | ||
{name: 'Tooth Fairy', | ||
hair: 'blue'} | ||
]; | ||
var resultDiv = $('<div></div>') | ||
|
||
var introParagraph = $('<p>My friends are:</p>'); | ||
resultDiv.append(introParagraph) | ||
|
||
for(var i = 0; i < friends.length; i++){ | ||
var resultParagraph = $('<p>' + describeFriend(friends[i]) + '</p>'); | ||
resultDiv.append(resultParagraph); | ||
} | ||
$('body').append(resultDiv); | ||
} | ||
function describeFriend(friend){ | ||
return "My friend " + friend.name + " has " + friend.hair + " hair. "; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
.box{ | ||
width: 100px; | ||
height: 200px; | ||
border: 1px solid #ccc; | ||
} |