Skip to content

Instantly share code, notes, and snippets.

@mcivorsteiner
Forked from dbc-challenges/jquery_example.html
Last active August 29, 2015 13:57
Show Gist options
  • Select an option

  • Save mcivorsteiner/9521753 to your computer and use it in GitHub Desktop.

Select an option

Save mcivorsteiner/9521753 to your computer and use it in GitHub Desktop.
Intro to jQuery for Phase 0
<!DOCTYPE html>
<html>
<head>
<title>DOM manipulation with jQuery</title>
<!-- Add a link to jQuery CDN here script here -->
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script type="text/javascript" src="jquery_example.js"></script>
</head>
<body>
<h1> Hello. Welcome to the jQuery DOM Manipulation Challenge! </h1>
<div class="mascot">
<h1> My DBC Mascot </h1>
<div id="logo">
<img src="http://s1.evcdn.com/images/edpborder500/I0-001/013/886/832-4.jpeg_/dev-bootcamp-hiring-day-32.jpeg">
</div>
</div>
<div id="buttons">
<button id="left">&laquo;</button>
<button id="right">&raquo;</button>
</div>
</body>
</html>
$(document).ready(function(){
//RELEASE 0:
//Link this script and the jQuery library to the jquery_example.html file and analyze what this code does.
$('body').css({'background-color': 'pink'});
//RELEASE 1:
//Add code here to select elements of the DOM
var h1 = $("h1");
var image = $("#logo img");
var logo = $('#logo');
//RELEASE 2:
// Add code here to modify the css and html of DOM elements
h1.css({'border': '2px solid black', 'color': 'blue'});
h1.first().css({'visibility': 'hidden'});
logo.prev().html("POCKET GOPHERS");
logo.css({'width': '563px', 'height': '563px', 'overflow': 'hidden'})
image.css({'height': '563px'})
//RELEASE 3: Event Listener
// Add the code for the event listener here
/*
image.on('mouseover', function(){
image.attr('src', 'http://richditch.wordpress.com/files/2009/04/pocket-gopher-052a-720.jpg')
})
image.on('mouseout', function(){
image.attr('src', 'http://s1.evcdn.com/images/edpborder500/I0-001/013/886/832-4.jpeg_/dev-bootcamp-hiring-day-32.jpeg')
})
*/
//RELEASE 4 : Experiment on your own
// Adding animation to the code from release 3 so that pictures fade in/out
image.on('mouseover', function() {
image.fadeOut(500,function(){
image.attr('src', 'http://richditch.wordpress.com/files/2009/04/pocket-gopher-052a-720.jpg')
image.fadeIn(500);
});
});
image.on('mouseout', function() {
image.fadeOut(500,function(){
image.attr('src', 'http://s1.evcdn.com/images/edpborder500/I0-001/013/886/832-4.jpeg_/dev-bootcamp-hiring-day-32.jpeg')
image.fadeIn(500);
});
});
// Adding functionality to move logo using right/left buttons
var right_btn = $('#right');
var left_btn = $('#left');
logo.css({'position': 'relative'});
right_btn.click(function() {
logo.animate({'left': '+=150px'}, 1000);
});
left_btn.click(function() {
logo.animate({'left': '-=150px'}, 1000);
});
}) // end of the document.ready function: do not remove or write DOM manipulation below this.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment