Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more DOM functionality #22

Merged
merged 1 commit into from Sep 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/css/base.scss
Expand Up @@ -154,6 +154,7 @@ body {
}

.startpage__footer--button {
opacity: 0;
background-color: #00000000;
border-radius: 10px;
border: 5px solid #BA38C4;
Expand Down Expand Up @@ -382,6 +383,7 @@ h3 {
background-color: #00000000;
font-size: 40px;
color: white;
padding-top: 6px;
font-family: 'Press Start 2P', cursive;
text-align: center;
box-shadow: 0 0 10px #f877ff;
Expand Down
4 changes: 2 additions & 2 deletions src/index.html
Expand Up @@ -16,12 +16,12 @@ <h1>COWBOYS <span>VS</span> ALIENS</h1>
</header>
<div class="startpage--players--container">
<div>
<img src="images/cowboy-icon.png" class="startpage--character--icon">
<img src="images/cowboy-icon.png" id="cowboy-image" class="startpage--character--icon">
<input placeholder="P1 NAME" style="text-transform:uppercase" class="startpage__input--player"
id="cowboy-name-input">
</div>
<div>
<img src="images/alien-icon.png" class="startpage--character--icon">
<img src="images/alien-icon.png" id="alien-image" class="startpage--character--icon">
<input placeholder="P2 NAME" style="text-transform:uppercase" class="startpage__input--player"
id="alien-name-input">
</div>
Expand Down
46 changes: 39 additions & 7 deletions src/index.js
Expand Up @@ -15,26 +15,58 @@ import './images/favicon-32x32.png';
import './images/favicon-16x16.png';
import './images/grainy-filter.jpg'
import './images/grainy-filter-2.png'
import Game from './Game';

const game = new Game()

const main = $('main');
const startGameButton = $('#start-game-button');
const exitButton = $('#exit-button');
const cowboyInput = $('#cowboy-name-input');
const alienInput = $('#alien-name-input');
const guessInput = $('#guess-input');
const guessButton = $('#guess-button');
const cowboyImage = $('#cowboy-image');
const alienImage = $('#alien-image');

window.onbeforeunload = function () {
window.scrollTo(0, 0);
}

cowboyInput.on('keyup', () => {
displayStartButton();
}).on('focus', () => {
cowboyImage.css('z-index', '1').animate({ height: '210px', width: '210px', marginBottom: '12px' }, 300);
}).on('focusout', () => {
cowboyImage.css('z-index', '0').animate({ height: '200px', width: '200px', marginBottom: '12px' }, 300);
})

alienInput.on('keyup', () => {
displayStartButton();
}).on('focus', () => {
alienImage.css('z-index', '1').animate({ height: '210px', width: '210px', marginBottom: '12px' }, 300);
}).on('focusout', () => {
alienImage.css('z-index', '0').animate({ height: '200px', width: '200px', marginBottom: '12px' }, 300);
})

startGameButton.on('click', () => {
$('#cowboy-name').text(cowboyInput.val());
$('#alien-name').text(alienInput.val());
$('#cowboy-name').text(cowboyInput.val().toUpperCase());
$('#alien-name').text(alienInput.val().toUpperCase());
$("html").delay(250).animate({ scrollTop: main.offset().top }, 1000)
})
setTimeout(function () {
cowboyInput.val('');
alienInput.val('');
startGameButton.css('opacity', '0');
}, 2000);
});

exitButton.on('click', () => {
$("html").delay(250).animate({ scrollTop: 0 }, 1000);
})
});

function displayStartButton() {
alienInput.val() === '' || cowboyInput.val() === ''
? startGameButton.animate({ opacity: '0' }, 100)
: startGameButton.animate({ opacity: '1' }, 100)
}

guessButton.on('click', () => {
guessInput.val('');
});