Last active
August 29, 2015 14:09
-
-
Save euclio/79bc0a4e3703663b585d to your computer and use it in GitHub Desktop.
Hack Week Day 2: JavaScript Tutorial
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
h1 { | |
font-family: "Comic Sans MS", sans-serif; | |
} | |
img { | |
margin: 3px; | |
} | |
#kittyville { | |
background-color: #3DBEFF; | |
display: inline-block; | |
} | |
.outline { | |
outline: 3px dashed black; | |
} | |
.kitty::after { | |
content: " 😻"; | |
} | |
.glow { | |
text-shadow: 0 0 20px blue; | |
} |
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
<!doctype html> | |
<html> | |
<head> | |
<title>JavaScript Tutorial</title> | |
<link rel="stylesheet" href="index.css"> | |
<meta charset="utf-8"> | |
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script> | |
<script src="index.js"></script> | |
</head> | |
<body> | |
<h1>Welcome to Kittyville</h1> | |
<div id="kittyville"> | |
<img class="kitty" src="http://storage.coolfeed.co/2012/10/Funny-Cat-Images-24-GIFs-coolfeed.co-4.gif" alt="Cat playing hide 'n' seek"> | |
</div> | |
<button id="showKittens">Find the Kittens</button> | |
<div> | |
<input id="favoriteThing" type="text" size="30" placeholder="Enter a favorite thing" /> | |
<button id="submit" type="submit">Enter</button> | |
<h1>My Favorite Things</h1> | |
<ul id="favoriteThings"> | |
<!-- No items yet --> | |
</ul> | |
</div> | |
<button id="checkFavorites">Check Favorites</button> | |
</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
$(document).ready(function() { | |
for (var i = 0; i < 3; i++) { | |
var $kittyImage = $('<img>') | |
.addClass('kitty') | |
.attr('src', 'http://storage.coolfeed.co/2012/10/Funny-Cat-Images-24-GIFs-coolfeed.co-4.gif') | |
.attr('alt', 'cute cat'); | |
$('#kittyville').append($kittyImage); | |
} | |
var $kitty = $(".kitty"); | |
$kitty.click(function() { | |
$(this).fadeOut(1000); | |
}); | |
$kitty.hover(function() { | |
$(this).toggleClass("outline"); | |
}); | |
$("#showKittens").click(function() { | |
var $kitties = $(".kitty"); | |
$kitties.each(function() { | |
$(this).show(); | |
}) | |
}); | |
$("#submit").click(function() { | |
var favoriteThing = $("#favoriteThing").val(); | |
if (!favoriteThing) { | |
return; | |
} | |
var $newThing = $("<li>"); | |
$newThing.text(favoriteThing); | |
$newThing.click(function() { | |
$(this).toggleClass("kitty"); | |
}); | |
$("#favoriteThings").append($newThing); | |
$("#favoriteThing").val(''); | |
}); | |
$("#checkFavorites").click(function() { | |
$("#favoriteThings li").each(function() { | |
if ($(this).text().toLowerCase() === 'cats') { | |
alert('OMG! I love cats too!'); | |
} | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment