Created
November 12, 2014 17:22
-
-
Save davidshimjs/0c1acf82a6f331bc98bf to your computer and use it in GitHub Desktop.
// source http://jsbin.com/foqadi
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<script src="http://cdnjs.cloudflare.com/ajax/libs/lodash.js/2.4.1/lodash.min.js"></script> | |
<script src="http://code.jquery.com/jquery-2.1.1.min.js"></script> | |
<script src="http://cdnjs.cloudflare.com/ajax/libs/moment.js/2.8.3/moment.min.js"></script> | |
<meta charset="utf-8"> | |
<title>JS Bin</title> | |
<style id="jsbin-css"> | |
* { | |
font-family: helvetica; | |
} | |
h1 { | |
font-family: malgun gothic; | |
} | |
.timer { | |
font-weight: bold; | |
background-color: #333; | |
color: yellow; | |
padding: 10px 15px; | |
font-size: 1.5em; | |
letter-spacing: 0.2em; | |
text-align: center; | |
} | |
li { | |
float: left; | |
width: 50%; | |
list-style-type: none; | |
border-bottom: 1px solid #ccc; | |
-webkit-transition: -webkit-transform 1s; | |
} | |
li h3 { | |
display: inline-block; | |
} | |
li .price { | |
font-size: 1.4em; | |
margin-left: 30px; | |
} | |
li .range { | |
display: inline-block; | |
margin-left: 10px; | |
} | |
li .range.red { | |
color: red; | |
font-weight: bold; | |
} | |
li .range.blue { | |
color: blue; | |
font-weight: bold; | |
} | |
li .range.none { | |
display: none; | |
} | |
</style> | |
</head> | |
<body> | |
<h1>폭풍의 증권시장</h1> | |
<div class="timer">00:00:00</div> | |
<div> | |
<ul class="list"> | |
</ul> | |
</div> | |
<script id="jsbin-javascript"> | |
// Round 1 | |
// var list = [ | |
// { | |
// name: '단절통신', | |
// price: 2000 | |
// }, { | |
// name: '사망생명', | |
// price: 2000 | |
// }, { | |
// name: '석기전자', | |
// price: 2000 | |
// }, { | |
// name: '지진건설', | |
// price: 2000 | |
// }, { | |
// name: '파산은행', | |
// price: 2000 | |
// }, { | |
// name: '왕따SNS', | |
// price: 2000 | |
// } | |
// ]; | |
// var data = [ | |
// [ 0, 0, 0, 0, 0, 0], // 00 | |
// [ 0, 400, 600, 0, 500, 0], // 05 | |
// [ 0,-400, 0, 400, 0, 600], // 10 | |
// [ 500, 0,-600,-300, 0, 0], // 15 | |
// [ 0, 0, 300, 600, 0,-1000], // 20 | |
// [-600, 100, 0, 0,-400, 0], // 25 | |
// [ 300, 900, 0,-900, 0, 0], // 30 | |
// [ 0, 0,-500, 0, 500,1000], // 35 | |
// [-200,-500, 0, 0,-100, 0], // 40 | |
// [ 0, 0, 500, 300, 0,-500], // 45 | |
// [ 500, 0,-600, 0, 0, 500], // 50 | |
// [-900,-800,-700, 0, 0, 0], // 55 | |
// [ 300, 500, 0, 0, 900, 0], // 60 | |
// ]; | |
// Round 2 | |
var list = [ | |
{ | |
name: '단절통신', | |
price: 1900 | |
}, { | |
name: '사망생명', | |
price: 2200 | |
}, { | |
name: '석기전자', | |
price: 1000 | |
}, { | |
name: '지진건설', | |
price: 2100 | |
}, { | |
name: '파산은행', | |
price: 3400 | |
}, { | |
name: '왕따SNS', | |
price: 2600 | |
} | |
]; | |
var data = [ | |
[ 0, 0, 0, 0, 0, 0], // 00 | |
[ 0, 0, 500, 0,-500, 500], // 05 | |
[ 400, 0, 0, 500, 0,-300], // 10 | |
[ 0, 0, 300,-700, 500, 0], // 15 | |
[ 500, 300, 0, 0, 0,1000], // 20 | |
[-100, 0, 0, 0, 300,-500], // 25 | |
[ 0,-100,1000, 500, 0, 0], // 30 | |
[ 0, 300, 0, 0,-900,-300], // 35 | |
[ 0, 0,-100, 100, 300, 0], // 40 | |
[ 500, 0, 200, 0, 0, 500], // 45 | |
[-800,-700,-800,-700,-900,-900], // 50(이벤트) | |
[ 500, 300, 500, 0, 0, 0], // 55 | |
[ 0, 0,1000,-500, 0,-800] // 60 | |
]; | |
var $list = $('.list'); | |
var currentMinutes = 0; | |
var currentIndex = -1; | |
function drawList(index) { | |
_.each(list, function (v, i) { | |
var className = ''; | |
var price = v.price; | |
var rangeInfo = _.isNumber(index) ? data[index] : []; | |
if (rangeInfo[i] > 0) { | |
className = 'red'; | |
} else if (rangeInfo[i] < 0) { | |
className = 'blue'; | |
} else { | |
className = 'none'; | |
} | |
for (j = 0; j <= index; j++) { | |
if (data[j]) { | |
price += data[j][i]; | |
} | |
} | |
var $el = $('<li data-list-index="' + i + '" data-range-index="' + index + '"><h3>' + v.name + '</h3><span class="price">' + numberFormat(price) + '원</span><span class="range ' + className + '">' + numberFormat(rangeInfo[i]) + '원</span></li>'); | |
var $beforeEl = $list.find('[data-list-index=' + i + ']'); | |
if ($beforeEl.length) { | |
if ($beforeEl.data('range-index') == index) { | |
return; | |
} | |
$beforeEl.css('webkitTransform', 'rotateX(360deg)').one('webkitTransitionEnd', function () { | |
$beforeEl.replaceWith($el); | |
}); | |
} else { | |
$el.appendTo($list); | |
} | |
}); | |
} | |
function drawTimer() { | |
var mins = moment().minutes(); | |
// var mins = moment().seconds(); | |
var index; | |
$('.timer').html(moment().format('HH:mm:ss')); | |
if (currentMinutes !== mins) { | |
currentMinutes = mins; | |
if (currentMinutes % 5 === 0) { | |
currentIndex++; | |
} | |
if (currentIndex >= 0 && currentIndex < data.length) { | |
drawList(currentIndex); | |
} | |
} | |
} | |
function numberFormat(nStr) { | |
nStr += ''; | |
x = nStr.split('.'); | |
x1 = x[0]; | |
x2 = x.length > 1 ? '.' + x[1] : ''; | |
var rgx = /(\d+)(\d{3})/; | |
while (rgx.test(x1)) { | |
x1 = x1.replace(rgx, '$1' + ',' + '$2'); | |
} | |
return x1 + x2; | |
} | |
setInterval(function () { | |
drawTimer(); | |
}, 1000); | |
</script> | |
<script id="jsbin-source-html" type="text/html"><!DOCTYPE html> | |
<html> | |
<head> | |
<script src="//cdnjs.cloudflare.com/ajax/libs/lodash.js/2.4.1/lodash.min.js"><\/script> | |
<script src="//code.jquery.com/jquery-2.1.1.min.js"><\/script> | |
<script src="//cdnjs.cloudflare.com/ajax/libs/moment.js/2.8.3/moment.min.js"><\/script> | |
<meta charset="utf-8"> | |
<title>JS Bin</title> | |
</head> | |
<body> | |
<h1>폭풍의 증권시장</h1> | |
<div class="timer">00:00:00</div> | |
<div> | |
<ul class="list"> | |
</ul> | |
</div> | |
</body> | |
</html></script> | |
<script id="jsbin-source-css" type="text/css">* { font-family: helvetica; } | |
h1 { | |
font-family: malgun gothic; | |
} | |
.timer { | |
font-weight: bold; | |
background-color: #333; | |
color: yellow; | |
padding: 10px 15px; | |
font-size: 1.5em; | |
letter-spacing: 0.2em; | |
text-align: center; | |
} | |
li { | |
float: left; | |
width: 50%; | |
list-style-type:none; | |
h3 { | |
display: inline-block; | |
} | |
.price { | |
font-size: 1.4em; | |
margin-left: 30px; | |
} | |
.range { | |
display: inline-block; | |
margin-left: 10px; | |
&.red { | |
color: red; | |
font-weight: bold; | |
} | |
&.blue { | |
color: blue; | |
font-weight: bold; | |
} | |
&.none { | |
display: none; | |
} | |
} | |
border-bottom: 1px solid #ccc; | |
-webkit-transition: -webkit-transform 1s; | |
}</script> | |
<script id="jsbin-source-javascript" type="text/javascript">// Round 1 | |
// var list = [ | |
// { | |
// name: '단절통신', | |
// price: 2000 | |
// }, { | |
// name: '사망생명', | |
// price: 2000 | |
// }, { | |
// name: '석기전자', | |
// price: 2000 | |
// }, { | |
// name: '지진건설', | |
// price: 2000 | |
// }, { | |
// name: '파산은행', | |
// price: 2000 | |
// }, { | |
// name: '왕따SNS', | |
// price: 2000 | |
// } | |
// ]; | |
// var data = [ | |
// [ 0, 0, 0, 0, 0, 0], // 00 | |
// [ 0, 400, 600, 0, 500, 0], // 05 | |
// [ 0,-400, 0, 400, 0, 600], // 10 | |
// [ 500, 0,-600,-300, 0, 0], // 15 | |
// [ 0, 0, 300, 600, 0,-1000], // 20 | |
// [-600, 100, 0, 0,-400, 0], // 25 | |
// [ 300, 900, 0,-900, 0, 0], // 30 | |
// [ 0, 0,-500, 0, 500,1000], // 35 | |
// [-200,-500, 0, 0,-100, 0], // 40 | |
// [ 0, 0, 500, 300, 0,-500], // 45 | |
// [ 500, 0,-600, 0, 0, 500], // 50 | |
// [-900,-800,-700, 0, 0, 0], // 55 | |
// [ 300, 500, 0, 0, 900, 0], // 60 | |
// ]; | |
// Round 2 | |
var list = [ | |
{ | |
name: '단절통신', | |
price: 1900 | |
}, { | |
name: '사망생명', | |
price: 2200 | |
}, { | |
name: '석기전자', | |
price: 1000 | |
}, { | |
name: '지진건설', | |
price: 2100 | |
}, { | |
name: '파산은행', | |
price: 3400 | |
}, { | |
name: '왕따SNS', | |
price: 2600 | |
} | |
]; | |
var data = [ | |
[ 0, 0, 0, 0, 0, 0], // 00 | |
[ 0, 0, 500, 0,-500, 500], // 05 | |
[ 400, 0, 0, 500, 0,-300], // 10 | |
[ 0, 0, 300,-700, 500, 0], // 15 | |
[ 500, 300, 0, 0, 0,1000], // 20 | |
[-100, 0, 0, 0, 300,-500], // 25 | |
[ 0,-100,1000, 500, 0, 0], // 30 | |
[ 0, 300, 0, 0,-900,-300], // 35 | |
[ 0, 0,-100, 100, 300, 0], // 40 | |
[ 500, 0, 200, 0, 0, 500], // 45 | |
[-800,-700,-800,-700,-900,-900], // 50(이벤트) | |
[ 500, 300, 500, 0, 0, 0], // 55 | |
[ 0, 0,1000,-500, 0,-800] // 60 | |
]; | |
var $list = $('.list'); | |
var currentMinutes = 0; | |
var currentIndex = -1; | |
function drawList(index) { | |
_.each(list, function (v, i) { | |
var className = ''; | |
var price = v.price; | |
var rangeInfo = _.isNumber(index) ? data[index] : []; | |
if (rangeInfo[i] > 0) { | |
className = 'red'; | |
} else if (rangeInfo[i] < 0) { | |
className = 'blue'; | |
} else { | |
className = 'none'; | |
} | |
for (j = 0; j <= index; j++) { | |
if (data[j]) { | |
price += data[j][i]; | |
} | |
} | |
var $el = $('<li data-list-index="' + i + '" data-range-index="' + index + '"><h3>' + v.name + '</h3><span class="price">' + numberFormat(price) + '원</span><span class="range ' + className + '">' + numberFormat(rangeInfo[i]) + '원</span></li>'); | |
var $beforeEl = $list.find('[data-list-index=' + i + ']'); | |
if ($beforeEl.length) { | |
if ($beforeEl.data('range-index') == index) { | |
return; | |
} | |
$beforeEl.css('webkitTransform', 'rotateX(360deg)').one('webkitTransitionEnd', function () { | |
$beforeEl.replaceWith($el); | |
}); | |
} else { | |
$el.appendTo($list); | |
} | |
}); | |
} | |
function drawTimer() { | |
var mins = moment().minutes(); | |
// var mins = moment().seconds(); | |
var index; | |
$('.timer').html(moment().format('HH:mm:ss')); | |
if (currentMinutes !== mins) { | |
currentMinutes = mins; | |
if (currentMinutes % 5 === 0) { | |
currentIndex++; | |
} | |
if (currentIndex >= 0 && currentIndex < data.length) { | |
drawList(currentIndex); | |
} | |
} | |
} | |
function numberFormat(nStr) { | |
nStr += ''; | |
x = nStr.split('.'); | |
x1 = x[0]; | |
x2 = x.length > 1 ? '.' + x[1] : ''; | |
var rgx = /(\d+)(\d{3})/; | |
while (rgx.test(x1)) { | |
x1 = x1.replace(rgx, '$1' + ',' + '$2'); | |
} | |
return x1 + x2; | |
} | |
setInterval(function () { | |
drawTimer(); | |
}, 1000); | |
</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
* { | |
font-family: helvetica; | |
} | |
h1 { | |
font-family: malgun gothic; | |
} | |
.timer { | |
font-weight: bold; | |
background-color: #333; | |
color: yellow; | |
padding: 10px 15px; | |
font-size: 1.5em; | |
letter-spacing: 0.2em; | |
text-align: center; | |
} | |
li { | |
float: left; | |
width: 50%; | |
list-style-type: none; | |
border-bottom: 1px solid #ccc; | |
-webkit-transition: -webkit-transform 1s; | |
} | |
li h3 { | |
display: inline-block; | |
} | |
li .price { | |
font-size: 1.4em; | |
margin-left: 30px; | |
} | |
li .range { | |
display: inline-block; | |
margin-left: 10px; | |
} | |
li .range.red { | |
color: red; | |
font-weight: bold; | |
} | |
li .range.blue { | |
color: blue; | |
font-weight: bold; | |
} | |
li .range.none { | |
display: none; | |
} |
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
// Round 1 | |
// var list = [ | |
// { | |
// name: '단절통신', | |
// price: 2000 | |
// }, { | |
// name: '사망생명', | |
// price: 2000 | |
// }, { | |
// name: '석기전자', | |
// price: 2000 | |
// }, { | |
// name: '지진건설', | |
// price: 2000 | |
// }, { | |
// name: '파산은행', | |
// price: 2000 | |
// }, { | |
// name: '왕따SNS', | |
// price: 2000 | |
// } | |
// ]; | |
// var data = [ | |
// [ 0, 0, 0, 0, 0, 0], // 00 | |
// [ 0, 400, 600, 0, 500, 0], // 05 | |
// [ 0,-400, 0, 400, 0, 600], // 10 | |
// [ 500, 0,-600,-300, 0, 0], // 15 | |
// [ 0, 0, 300, 600, 0,-1000], // 20 | |
// [-600, 100, 0, 0,-400, 0], // 25 | |
// [ 300, 900, 0,-900, 0, 0], // 30 | |
// [ 0, 0,-500, 0, 500,1000], // 35 | |
// [-200,-500, 0, 0,-100, 0], // 40 | |
// [ 0, 0, 500, 300, 0,-500], // 45 | |
// [ 500, 0,-600, 0, 0, 500], // 50 | |
// [-900,-800,-700, 0, 0, 0], // 55 | |
// [ 300, 500, 0, 0, 900, 0], // 60 | |
// ]; | |
// Round 2 | |
var list = [ | |
{ | |
name: '단절통신', | |
price: 1900 | |
}, { | |
name: '사망생명', | |
price: 2200 | |
}, { | |
name: '석기전자', | |
price: 1000 | |
}, { | |
name: '지진건설', | |
price: 2100 | |
}, { | |
name: '파산은행', | |
price: 3400 | |
}, { | |
name: '왕따SNS', | |
price: 2600 | |
} | |
]; | |
var data = [ | |
[ 0, 0, 0, 0, 0, 0], // 00 | |
[ 0, 0, 500, 0,-500, 500], // 05 | |
[ 400, 0, 0, 500, 0,-300], // 10 | |
[ 0, 0, 300,-700, 500, 0], // 15 | |
[ 500, 300, 0, 0, 0,1000], // 20 | |
[-100, 0, 0, 0, 300,-500], // 25 | |
[ 0,-100,1000, 500, 0, 0], // 30 | |
[ 0, 300, 0, 0,-900,-300], // 35 | |
[ 0, 0,-100, 100, 300, 0], // 40 | |
[ 500, 0, 200, 0, 0, 500], // 45 | |
[-800,-700,-800,-700,-900,-900], // 50(이벤트) | |
[ 500, 300, 500, 0, 0, 0], // 55 | |
[ 0, 0,1000,-500, 0,-800] // 60 | |
]; | |
var $list = $('.list'); | |
var currentMinutes = 0; | |
var currentIndex = -1; | |
function drawList(index) { | |
_.each(list, function (v, i) { | |
var className = ''; | |
var price = v.price; | |
var rangeInfo = _.isNumber(index) ? data[index] : []; | |
if (rangeInfo[i] > 0) { | |
className = 'red'; | |
} else if (rangeInfo[i] < 0) { | |
className = 'blue'; | |
} else { | |
className = 'none'; | |
} | |
for (j = 0; j <= index; j++) { | |
if (data[j]) { | |
price += data[j][i]; | |
} | |
} | |
var $el = $('<li data-list-index="' + i + '" data-range-index="' + index + '"><h3>' + v.name + '</h3><span class="price">' + numberFormat(price) + '원</span><span class="range ' + className + '">' + numberFormat(rangeInfo[i]) + '원</span></li>'); | |
var $beforeEl = $list.find('[data-list-index=' + i + ']'); | |
if ($beforeEl.length) { | |
if ($beforeEl.data('range-index') == index) { | |
return; | |
} | |
$beforeEl.css('webkitTransform', 'rotateX(360deg)').one('webkitTransitionEnd', function () { | |
$beforeEl.replaceWith($el); | |
}); | |
} else { | |
$el.appendTo($list); | |
} | |
}); | |
} | |
function drawTimer() { | |
var mins = moment().minutes(); | |
// var mins = moment().seconds(); | |
var index; | |
$('.timer').html(moment().format('HH:mm:ss')); | |
if (currentMinutes !== mins) { | |
currentMinutes = mins; | |
if (currentMinutes % 5 === 0) { | |
currentIndex++; | |
} | |
if (currentIndex >= 0 && currentIndex < data.length) { | |
drawList(currentIndex); | |
} | |
} | |
} | |
function numberFormat(nStr) { | |
nStr += ''; | |
x = nStr.split('.'); | |
x1 = x[0]; | |
x2 = x.length > 1 ? '.' + x[1] : ''; | |
var rgx = /(\d+)(\d{3})/; | |
while (rgx.test(x1)) { | |
x1 = x1.replace(rgx, '$1' + ',' + '$2'); | |
} | |
return x1 + x2; | |
} | |
setInterval(function () { | |
drawTimer(); | |
}, 1000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment