-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 1894258
Showing
7 changed files
with
1,141 additions
and
0 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<!doctype html> | ||
<html class="no-js"> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>bonusTime</title> | ||
<meta name="description" content=""> | ||
<meta name="viewport" content="width=device-width"> | ||
<link rel="shortcut icon" href="favicon.7afe6f60.ico"> | ||
<link href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"> | ||
<link rel="stylesheet" href="scripts.72999ec6.css"> | ||
</head> | ||
<body> | ||
<!--[if lt IE 10]> | ||
<p class="browsehappy">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade | ||
your browser</a> to improve your experience.</p> | ||
<![endif]--> | ||
<div id="container" class="container"> | ||
<div id="stage"> | ||
<div id="shape" class="cube backfaces cubeShow_0"> | ||
<div id="card0" class="plane one">0</div> | ||
<div id="card1" class="plane two">1</div> | ||
<div id="card2" class="plane three">2</div> | ||
<div id="card3" class="plane four">3</div> | ||
<div id="card4" class="plane five">4</div> | ||
<div id="card5" class="plane six">5</div> | ||
<div id="card6" class="plane seven">6</div> | ||
<div id="card7" class="plane eight">7</div> | ||
<div id="card8" class="plane nine">8</div> | ||
<div id="card9" class="plane ten">9</div> | ||
</div> | ||
</div> | ||
<div class="row"> | ||
<div class="col-xs-4"> | ||
<div id="num1" class="showNum"></div> | ||
</div> | ||
<div class="col-xs-4"> | ||
<div id="num2" class="showNum"></div> | ||
</div> | ||
<div class="col-xs-4"> | ||
<div id="num3" class="showNum"></div> | ||
</div> | ||
<div class="col-xs-4"> | ||
<div id="num4" class="showNum"></div> | ||
</div> | ||
</div> | ||
</div> | ||
<script src="https://cdn.staticfile.org/jquery/3.2.1/jquery.min.js"></script> | ||
<script> | ||
!function(e, a, t, n, g, c) { | ||
e.GoogleAnalyticsObject = n, | ||
e.ga || (e.ga = function() { | ||
(e.ga.q = e.ga.q || []).push(arguments) | ||
} | ||
), | ||
e.ga.l = +new Date, | ||
g = a.createElement(t), | ||
c = a.getElementsByTagName(t)[0], | ||
g.src = "//www.google-analytics.com/analytics.js", | ||
c.parentNode.insertBefore(g, c) | ||
}(window, document, "script", "ga"), | ||
ga("create", "UA-XXXXX-X"), | ||
ga("send", "pageview"); | ||
</script> | ||
<script src="https://cdn.staticfile.org/twitter-bootstrap/4.0.0-beta.2/js/bootstrap.bundle.min.js"></script> | ||
<script src="index.js"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
/* | ||
原网址: https://camuskit-bonustime.netlify.com/ | ||
感谢作者把代码写得如此清晰而通用. 所有写出整洁代码的人都值得尊敬. | ||
BearDic, 2018-10-29. | ||
*/ | ||
|
||
$(document).ready(function () { | ||
console.log('%c原网址: https://camuskit-bonustime.netlify.com/', 'color:blue;font-size:1.5em'); | ||
console.log('%c感谢原作者把代码写得如此清晰而通用. 所有写出整洁代码的人都值得尊敬.', 'color:blue;font-size:1.5em'); | ||
console.log('%cBearDic, 2018-10-29. ', 'color:black;font-size:1.2em'); | ||
var getConfig = function () { | ||
const url = new URL(window.location.href); | ||
var minNum = 1, maxNum = 999, size = 4, hasBackground = false, cardBackground = false, showMode = 0; | ||
|
||
minNum = parseInt(url.searchParams.get("min") || "1"); | ||
maxNum = parseInt(url.searchParams.get("max") || "999"); | ||
if (maxNum<1000) | ||
{ | ||
$("#num4").parent().remove(); | ||
$(".col-xs-4").css("width","33.33333333%"); | ||
size=3; | ||
} | ||
else size = 4; | ||
const customBackground = url.searchParams.get("bg_url"); | ||
cardBackground = false; | ||
showMode = 1; | ||
return [minNum, maxNum, size, customBackground, cardBackground, showMode]; | ||
}; | ||
|
||
// Add special background | ||
var addBackground = function (bgUrl) { | ||
$('body').css('background-image', `url(${bgUrl})`); | ||
}; | ||
var addCardBackground = function () { | ||
for (var i = 0; i < 10; i++) { | ||
$('#card' + i).css('background', 'url(\'images/' + i + '.jpg\') no-repeat center 200px').text(''); | ||
} | ||
}; | ||
|
||
// Get a random number, and return as a string array | ||
var getRandomNum = function (usedNum, minNum, maxNum, size) { | ||
var randomNum = Math.round(Math.random() * (maxNum - minNum + 1) + minNum-0.5); | ||
|
||
while(Math.floor(randomNum/10)-randomNum%10 == 0) | ||
randomNum = Math.round(Math.random() * (maxNum - minNum + 1) + minNum-0.5); | ||
usedNum.push(randomNum); | ||
var str = randomNum.toString(); | ||
while (str.length < size) str = '0' + str; | ||
//str = str.substr(0,1) + '&' + str.substr(1,1); | ||
//str = '??' + str; | ||
return str.split(''); | ||
}; | ||
|
||
// Toggle between Cube and Ring | ||
var toggleShape = function () { | ||
$('#shape').toggleClass('ring').toggleClass('cube'); | ||
}; | ||
|
||
// Open ring and show num, or inversely | ||
var toggleBetweenNumAndCube = function (ringNum, cubeNum) { | ||
var $shape = $('#shape'); | ||
$shape.toggleClass('ringShow_' + ringNum).toggleClass('cubeShow_' + cubeNum); | ||
$shape.css('-webkit-transform', 'rotateY(' + (-36 * ringNum) + 'deg)'); | ||
}; | ||
|
||
// Let card jump | ||
var toggleCardJump = function (num) { | ||
$('#card' + num).toggleClass('jump' + num); | ||
}; | ||
|
||
// Write the number into num block | ||
var displayNum = function (cardNum, showNum) { | ||
$('#num' + cardNum).text(showNum); | ||
}; | ||
|
||
// Let the number jump | ||
var toggleNumJump = function (num) { | ||
$('#num' + num).toggleClass('jumpDown'); | ||
}; | ||
|
||
// The whole lottery process with one num | ||
var showNumByTurn = function (times, targetNum, originNum) { | ||
toggleShape(); | ||
toggleBetweenNumAndCube(targetNum, originNum); | ||
setTimeout(function () { | ||
toggleCardJump(numArr[times]); | ||
setTimeout(function () { | ||
displayNum(times + 1, numArr[times]); | ||
toggleNumJump(times + 1); | ||
toggleShape(); | ||
toggleBetweenNumAndCube(targetNum, targetNum); | ||
toggleCardJump(numArr[times]); | ||
}, 1100); | ||
}, 3300); | ||
}; | ||
|
||
// Show all num once | ||
var showNumOnce = function (numArr) { | ||
for (var i = 0; i < numArr.length; i++) { | ||
displayNum(i + 1, numArr[i]); | ||
toggleNumJump(i + 1); | ||
} | ||
}; | ||
|
||
// clear numbers | ||
var clearNum = function (arr) { | ||
for (var i = 0; i < arr.length; i++) { | ||
toggleNumJump(i + 1); | ||
$('#num' + (i + 1)).text(''); | ||
} | ||
}; | ||
|
||
// 0: minNum, 1: maxNum, 2: numLength, 3: hasBackground. | ||
var config = getConfig(); | ||
|
||
// Add background | ||
if (config[3]) | ||
addBackground(config[3]); | ||
if (config[4]) | ||
addCardBackground(); | ||
|
||
// Lottery | ||
var usedArr = []; | ||
var numArr = getRandomNum(usedArr, config[0], config[1], config[2]); | ||
var pressTimes = 0, preNum = 0; | ||
$('body').keydown(function (event) { | ||
if (config[5] === 0) { | ||
if (event.which === 32) { | ||
if (pressTimes < numArr.length) { | ||
showNumByTurn(pressTimes, numArr[pressTimes], preNum); | ||
preNum = numArr[pressTimes]; | ||
pressTimes++; | ||
} else { | ||
pressTimes = 0; | ||
clearNum(numArr); | ||
numArr = getRandomNum(usedArr, config[0], config[1], config[2]); | ||
} | ||
} | ||
} else if (config[5] === 1) { | ||
if (event.which === 32 && pressTimes === 0) { | ||
toggleShape(); | ||
pressTimes++; | ||
} else if (event.which === 32 && pressTimes === 1) { | ||
toggleShape(); | ||
showNumOnce(numArr); | ||
pressTimes++; | ||
} else if (event.which === 32 && pressTimes === 2) { | ||
clearNum(numArr); | ||
numArr = getRandomNum(usedArr, config[0], config[1], config[2]); | ||
pressTimes = 0; | ||
} | ||
} | ||
}) | ||
}); |
Oops, something went wrong.