i, i, i all you hear is i. iPhone, iLife and now also iScout. iScout is a game for scouts where they have to solve puzzles and perform crazy exercises. Like last year we participated and I wanted to share one of the exercises we had to do.
The description was “Built a opening ceremony 2.0” and nerds as we are we immediately thought of a jQuery solution. So we started thinking and worked out a simple idea.
The HTML consists of just 2 div elements and 2 buttons, we could get the same result with one but for simplicity this was chosen.
<div id="mast"></div>
<div id="vlag"></div>
<button id="hijs">Hijs vlag!</button>
<button id="strijk">Strijk Vlag!</button>
The CSS, we used a gradient for the creation of a Dutch flag.
#mast {
width: 10px;
height: 200px;
border:1px solid #000;
border-radius: 5px;
}
#vlag {
width: 100px;
height: 50px;
position: absolute;
left: 10px;
top: 150px;
background: #ff0000; /* Old browsers */
background: -moz-linear-gradient(top, #ff0000 0%, #ffffff 50%, #0000ff 100%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#ff0000), color-stop(50%,#ffffff), color-stop(100%,#0000ff)); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(top, #ff0000 0%,#ffffff 50%,#0000ff 100%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(top, #ff0000 0%,#ffffff 50%,#0000ff 100%); /* Opera 11.10+ */
background: -ms-linear-gradient(top, #ff0000 0%,#ffffff 50%,#0000ff 100%); /* IE10+ */
background: linear-gradient(top, #ff0000 0%,#ffffff 50%,#0000ff 100%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#ff0000', endColorstr='#0000ff',GradientType=0 ); /* IE6-9 */
}
And the jQuery for handling the required events.
$('#vlag').hide();
$('#strijk').hide();
$('#hijs').click(function() {
$('#vlag').fadeIn().animate({
"top": "5px"
}, 3000);
$('#hijs').fadeOut(function() {
$('#strijk').fadeIn()
});
});
$('#strijk').click(function() {
$('#vlag').fadeIn().animate({
"top": "150px"
}, 3000).fadeOut();
$('#strijk').fadeOut(function() {
$('#hijs').fadeIn()
});
});
Check jsfiddle for the result.