Skip to content

Instantly share code, notes, and snippets.

@cmendesce
Created June 1, 2020 14:23
Show Gist options
  • Select an option

  • Save cmendesce/9eabde188d86dc37aa3812ea214d380b to your computer and use it in GitHub Desktop.

Select an option

Save cmendesce/9eabde188d86dc37aa3812ea214d380b to your computer and use it in GitHub Desktop.
var app = angular.module('catsvsdogs', []);
var socket = io.connect({transports:['polling']});
var bg1 = document.getElementById('background-stats-1');
var bg2 = document.getElementById('background-stats-2');
app.controller('statsCtrl', function($scope){
$scope.aPercent = 50;
$scope.bPercent = 50;
var updateScores = function(){
socket.on('scores', function (json) {
data = JSON.parse(json);
var a = parseInt(data.a || 0);
var b = parseInt(data.b || 0);
var percentages = getPercentages(a, b);
bg1.style.width = percentages.a + "%";
bg2.style.width = percentages.b + "%";
$scope.$apply(function () {
$scope.aPercent = percentages.a;
$scope.bPercent = percentages.b;
$scope.total = a + b;
});
});
};
var init = function(){
document.body.style.opacity=1;
updateScores();
};
socket.on('message',function(data){
init();
});
});
function getPercentages(a, b) {
var result = {};
if (a + b > 0) {
result.a = Math.round(a / (a + b) * 100);
result.b = 100 - result.a;
} else {
result.a = result.b = 50;
}
return result;
}
@import url(//fonts.googleapis.com/css?family=Open+Sans:400,700,600);
*{
box-sizing:border-box;
}
html,body{
margin:0;
padding:0;
height:100%;
font-family: 'Open Sans';
}
body{
opacity:0;
transition: all 1s linear;
}
.divider{
height: 150px;
width:2px;
background-color: #C0C9CE;
position: relative;
top: 50%;
float: left;
transform: translateY(-50%);
}
#background-stats-1{
background-color: #2196f3;
}
#background-stats-2{
background-color: #00cbca;
}
#content-container{
z-index:2;
position:relative;
margin:0 auto;
display:table;
padding:10px;
max-width:940px;
height:100%;
}
#content-container-center{
display:table-cell;
text-align:center;
vertical-align:middle;
}
#result{
z-index: 3;
position: absolute;
bottom: 40px;
right: 20px;
color: #fff;
opacity: 0.5;
font-size: 45px;
font-weight: 600;
}
#choice{
transition: all 300ms linear;
line-height:1.3em;
background:#fff;
box-shadow: 10px 0 0 #fff, -10px 0 0 #fff;
vertical-align:middle;
font-size:40px;
font-weight: 600;
width: 450px;
height: 200px;
}
#choice a{
text-decoration:none;
}
#choice a:hover, #choice a:focus{
outline:0;
text-decoration:underline;
}
#choice .choice{
width: 49%;
position: relative;
top: 50%;
transform: translateY(-50%);
text-align: left;
padding-left: 50px;
}
#choice .choice .label{
text-transform: uppercase;
}
#choice .choice.dogs{
color: #00cbca;
float: right;
}
#choice .choice.cats{
color: #2196f3;
float: left;
}
#background-stats{
z-index:1;
height:100%;
width:100%;
position:absolute;
}
#background-stats div{
transition: width 400ms ease-in-out;
display:inline-block;
margin-bottom:-4px;
width:50%;
height:100%;
}
@import url(//fonts.googleapis.com/css?family=Open+Sans:400,700,600);
*{
box-sizing:border-box;
}
html,body{
margin: 0;
padding: 0;
background-color: #F7F8F9;
height: 100vh;
font-family: 'Open Sans';
}
button{
border-radius: 0;
width: 100%;
height: 50%;
}
button[type="submit"] {
-webkit-appearance:none; -webkit-border-radius:0;
}
button i{
float: right;
padding-right: 30px;
margin-top: 3px;
}
button.a{
background-color: #1aaaf8;
}
button.b{
background-color: #00cbca;
}
#tip{
text-align: left;
color: #c0c9ce;
font-size: 14px;
}
#hostname{
position: absolute;
bottom: 100px;
right: 0;
left: 0;
color: #8f9ea8;
font-size: 24px;
}
#content-container{
z-index: 2;
position: relative;
margin: 0 auto;
display: table;
padding: 10px;
max-width: 940px;
height: 100%;
}
#content-container-center{
display: table-cell;
text-align: center;
}
#content-container-center h3{
color: #254356;
}
#choice{
transition: all 300ms linear;
line-height: 1.3em;
display: inline;
vertical-align: middle;
font-size: 3em;
}
#choice a{
text-decoration:none;
}
#choice a:hover, #choice a:focus{
outline:0;
text-decoration:underline;
}
#choice button{
display: block;
height: 80px;
width: 330px;
border: none;
color: white;
text-transform: uppercase;
font-size:18px;
font-weight: 700;
margin-top: 10px;
margin-bottom: 10px;
text-align: left;
padding-left: 50px;
}
#choice button.a:hover{
background-color: #1488c6;
}
#choice button.b:hover{
background-color: #00a2a1;
}
#choice button.a:focus{
background-color: #1488c6;
}
#choice button.b:focus{
background-color: #00a2a1;
}
#background-stats{
z-index:1;
height:100%;
width:100%;
position:absolute;
}
#background-stats div{
transition: width 400ms ease-in-out;
display:inline-block;
margin-bottom:-4px;
width:50%;
height:100%;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment