Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
todd404 committed Apr 6, 2019
1 parent e6c404a commit d2fd219
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 40 deletions.
2 changes: 1 addition & 1 deletion assets/js/bundle.js

Large diffs are not rendered by default.

10 changes: 9 additions & 1 deletion src/css/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,14 @@ body{
.plus_box {
position: fixed;
font-size: 100px;
width: 15%;
color: #F08080;

width: 20%;
height: 15%;
text-align: center;

z-index: 100;

display: none;
opacity: 0;
}
Expand Down Expand Up @@ -77,6 +81,10 @@ body{
z-index : 0;
left : calc(50% - 13vw);

/*background: url("../img/teamB.jpg") no-repeat;
background-size: contain;
background-position: bottom center;*/

opacity: .6;
}

Expand Down
Binary file added src/img/teamB.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
127 changes: 90 additions & 37 deletions src/js/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,97 @@ var $ = require("jquery");

var totalVotes = 0;
var votes = new Array();
votes["teamBtn1"] = 0;
votes["teamBtn2"] = 0;
votes["teamBtn3"] = 0;
votes["teamBtn1"] = {score: 0, leaderScore: 0};
votes["teamBtn2"] = {score: 0, leaderScore: 0};
votes["teamBtn3"] = {score: 0, leaderScore: 0};

function insertStr(soure, start, newStr) {

return soure.slice(0, start) + newStr + soure.slice(start);
}

function initAnimates() {
$(".team2_button").addClass("bounceIn");

setTimeout(() => {
$(".team1_button").addClass("moveToLeft");
$(".team3_button").addClass("moveToRight");
}, 1000);

setTimeout(() => {
$(".title_box").addClass("show");
}, 2000)

setTimeout(() => {
$(".input").addClass("show");
}, 3000)
}

function setEvents() {

$(".input__field").focus(function () {
$(this).parent().addClass("input--filled");
})

$(".input__field").blur(function () {

var teamBtnName = $(this).attr("id");
var reg = new RegExp("_input")
teamBtnName = teamBtnName.replace(reg, "")
teamBtnName = insertStr(teamBtnName, teamBtnName.length - 1, "Btn");

if ($(this).val() === "") {
$(this).parent().removeClass("input--filled");
votes[teamBtnName].leaderScore = 0;
} else {
votes[teamBtnName].leaderScore = Number($(this).val());
}
})

$(".buttons").on("click", ".button", function () {

var leaderScoreFlag = true;

for (var x in votes) {
if (votes[x].leaderScore === 0) {
showPlusMessage($(this), "😑");
leaderScoreFlag = false;
break;
}
}

if (leaderScoreFlag) vote($(this));
});
}

function account() {

var top = "teamBtn1";

for (var x in votes) {
if (x === "teamBtn1") continue;

if (votes[x].score > votes[top].score) {
top = x;
continue;
} else if (votes[x].score === votes[top].score) {
if (votes[x].leaderScore > votes[top].leaderScore) {
top = x;
continue;
}
}
}

console.log(top);
}

function showPlusMessage(currentButton, messgage) {
var top = currentButton.css("top"),
left = currentButton.css("left"),
right = currentButton.css("right");

$(".plus_box").css("top", "calc( " + top + " + 13vw - 7.5% )");
$(".plus_box").css("left","calc( " + left + " + 13vw - 7.5% )");
$(".plus_box").css("right","calc( " + right + " + 13vw - 7.5% )");
$(".plus_box").css("top", "calc( " + top + " + 13vw - 10% )");
$(".plus_box").css("left", "calc( " + left + " + 13vw - 10% )");
$(".plus_box").css("right", "calc( " + right + " + 13vw - 10% )");

$(".plus_box").text(messgage);

Expand All @@ -32,37 +107,15 @@ function showPlusMessage(currentButton, messgage) {

function vote(currentTeam) {
totalVotes++;
console.log(currentTeam.attr("id"));
votes[currentTeam.attr("id")]++;
showPlusMessage(currentTeam, votes[currentTeam.attr("id")] + " 票");
votes[currentTeam.attr("id")].score++;
showPlusMessage(currentTeam, votes[currentTeam.attr("id")].score + " 票 🥳");

if (totalVotes == 7) {
account();
}
}

export function init(){
$(".team2_button").addClass("bounceIn");

$(".input__field").focus(function () {
$(this).parent().addClass("input--filled");
})
$(".input__field").blur(function () {
console.log($(this).val());
if($(this).val() == ""){$(this).parent().removeClass("input--filled")}
})

$(".buttons").on("click", ".button", function () {
vote($(this));
});

setTimeout(()=>{
$(".team1_button").addClass("moveToLeft");
$(".team3_button").addClass("moveToRight");
}, 1000);

setTimeout(()=>{
$(".title_box").addClass("show");
}, 2000)

setTimeout(()=>{
$(".input").addClass("show");
}, 3000)

setEvents();
initAnimates();
}
6 changes: 5 additions & 1 deletion webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
path: __dirname + "/assets/js",//打包后的文件存放的地方
filename: "bundle.js"//打包后输出文件的文件名
},
devtool: 'eval-source-map',
devtool: 'null',
module: {
rules: [
{
Expand Down Expand Up @@ -44,6 +44,10 @@
}
]
},
{
test: /\.(png|jpg)$/,
loader: 'url-loader?limit=8192&name=../images/[hash:8].[name].[ext]'
}
]
},
externals: {
Expand Down

0 comments on commit d2fd219

Please sign in to comment.