[Day5] JS 5 [11/24]
--๋ณต์ต--
1. ๋ก๋ ๋ฒํธ ๋ฐ์๊ธฐ ๋ฒํผ์ ํด๋ฆญํ๋ฉด ๋ก๋ ๋ฒํธ๊ฐ p ํ๊ทธ์ ์ถ๋ ฅ๋๋๋ก js ์ฝ๋ฉ ํ์ธ์
( ์กฐ๊ฑด : ์ค๋ฆ์ฐจ์ ์ ๋ ฌ ํด์ ์ถ๋ ฅ )
<button>๋ก๋ ๋ฒํธ ๋ฐ์๊ธฐ</button>
<p id="demo"></p>
$("button").click( function (){
// alert("1")
// js ๋ฐฐ์ด ์ ์ธ
var lotto = [];
var n ;
while ( lotto.length < 6 ) {
n = getRndRange( 1, 45);
if( isDuplicationLotto(lotto, n) ) lotto.push( n );
//lotto.push(n);
} //
lotto.sort( (a,b) => a-b );
$("#demo").html( "<ul><li>" + lotto.join("</li><li>") +" </li></ul>");
});
// 1. min ~ max ๋ฐ์์ํค๋ ํจ์
function getRndRange( min, max){
return Math.floor( Math.random()*(max-min+1) ) + min;
}
// 2. ์ค๋ณต ์ฒดํฌํ๋ ํจ์
function isDuplicationLotto( lotto, n ){
return lotto.every( (elt, i, array) => elt != n ) ;
/*
return lotto.every(function(elt, i, array) {
return elt != n ;
})
*/
}
2.
ใฑ. select ํ๊ทธ์ 1์์ 20๊น์ง์ option ํ๊ทธ๋ฅผ js๋ก ์ถ๊ฐํ๊ณ
ใด. ๋ก๋ ๊ฒ์ ํ์๋ฅผ select ํ๊ทธ์์ ์ ํ ํ ๋ก๋ ๋ฒํธ ์ถ๋ ฅํ๋ js ์ฝ๋ฉํ์ธ์.
<select id="cmbCnt"></select>
<br>
<button>๋ก๋ ๋ฒํธ ๋ฐ์๊ธฐ</button>
<p id="demo"></p>
<script>
// 1. select ์์์ options 20๊ฐ ์ถ๊ฐ
for (var i = 1; i <= 20; i++) {
$("#cmbCnt").append( $("<option></option>").text( i ).val( i ) );
} // for
/* [1์กฐ]
var op = "";
for (var i = 1; i <= 20; i++) {
op += "<option value=" + i + ">" + i + "</option>";
}
// document.getElementById("cmbCnt").innerHTML = op;
$("#cmbCnt").html( op );
*/
// 2. [jquery ajax ] - on(์ด๋ฒคํธ ๋ฑ๋ก)
$("button").on("click", function() {
// js ์ปฌ๋ ์
ํด๋์ค( list, set, map )
var lottos = []; // 2์ฐจ์ ๋ฐฐ์ด
// selected option์ value ์์ฑ
var gCnt = $("#cmbCnt").val();
// alert( gCnt );
for (var i = 1; i <= gCnt; i++) {
var lotto = [];
var n ;
while ( lotto.length < 6 ) {
n = getRndRange( 1, 45);
if( isDuplicationLotto(lotto, n) ) lotto.push( n );
//lotto.push(n);
} // while
lotto.sort( (a,b) => a-b );
lottos.push( lotto );
} // for
$("#demo").html( lottos.join("<br>").toString() );
});
// [ lotto.js ์ธ๋ถjs ]
// 1. min ~ max ๋ฐ์์ํค๋ ํจ์
function getRndRange( min, max){
return Math.floor( Math.random()*(max-min+1) ) + min;
}
// 2. ์ค๋ณต ์ฒดํฌํ๋ ํจ์
function isDuplicationLotto( lotto, n ){
return lotto.every( (elt, i, array) => elt != n ) ;
/*
return lotto.every(function(elt, i, array) {
return elt != n ;
})
*/
}
</script>
3. ๊ตฌ๊ตฌ๋จ ์ถ๋ ฅ ๋ฒํผ์ ํด๋ฆญํ๋ฉด p ํ๊ทธ์ ํ ์ด๋ธ ํ์์ผ๋ก ๊ตฌ๊ตฌ๋จ ์ถ๋ ฅํ๋ js ์ฝ๋ฉํ์ธ์ .
<button>๊ตฌ๊ตฌ๋จ ์ถ๋ ฅ ๋ฒํผ</button>
<p id="demo"></p>
// ๊ตฌ๊ตฌ๋จ ๊ฐ๋ก, ์ธ๋ก ์ถ๋ ฅ
var content = "<table border='1' width='100%''>";
// 2๋จ 3๋จ ~ 9๋จ th
content += "<tr>";
for (var i = 2; i <=9; i++) {
content += "<th>"+i+"๋จ</th>";
}
content += "</tr>";
//
for (var i = 1; i <=9 ; i++) {
content += "<tr>";
for (var j = 2; j <= 9; j++) {
content += "<td>";
content += j + " * " + i + " = " + ( j*i );
content += "</td>";
} // for j
content += "</tr>";
} // for i
content += "</table>";
// js innerText == jquery text()
// js innerHTML == jquery html()
$("#demo").html( content );
์ฃผ๋ฏผ๋ฒํธ ๋ง๋์ด
// ์ฃผ๋ฏผ๋ฑ๋ก๋ฒํธ -> ๋ง๋์ด .
function getAge( rrn ){
// "890123-1700001"
/*
rrn.substr(from, length);
rrn.substring(from, to)
rrn.slice(from, to);
*/
// 89
var bYear = getCentry(rrn) + parseInt( rrn.substr( 0, 2 ) );
// 01
var bMonth = parseInt( rrn.substring(2 , 4) );
// 23
var bDate = parseInt( rrn.slice(4 , 6) );
// 1
// var bGender = rrn.slice( -7, -6)
var bGender = rrn.substr( 7, 1 );
console.log( bYear +" / " + bMonth + " / " + bDate + " / " + bGender);
// 2022 - 1989 ์ฌํด๋
๋ - ์์ผ๋
๋
var today = new Date();
var todayYear = today.getFullYear();
var age = todayYear - bYear;
// ์ค๋ ์์ผ ์ง๋ฌ์ง ์์์ผ๋ฉด -1
// js ๋ ์ง > ๋ ์ง
// js ๋ ์ง < ๋ ์ง ๋น๊ต์ฐ์ฐ์
// js ๋ ์ง == ๋ ์ง ๋น๊ต์ฐ์ฐ์
var birthday = new Date( todayYear, bMonth-1, bDate);
today.setHours(0);
today.setMinutes(0);
today.setSeconds(0);
today.setMilliseconds(0);
if( today < birthday ) age--;
console.log( birthday.toLocaleString() ) ;
console.log( today.toLocaleString() ) ;
return age;
}
function getCentry( rrn ){
var gender = rrn.substr( 7, 1 );
// 1,2,5,6 1900
// 3,4,7,8 2000
// 9,0 1800
if( [1,2,5,6].some((elt, i, array) => elt == gender ) ) return 1900;
else if( [3,4,7,8].some((elt, i, array) => elt == gender ) ) return 2000;
else return 1800;
}
// ๋ง๋์ด ์์ผ ์ง๋ ์ํ : 33
// X ์ํ : 32
console.log( "> ๋ง ๋์ด : " + getAge("891125-1700001") );
๋ฌ๋ ฅ( ์ผ์ ๊ด๋ฆฌ )
<style>
select {
width: 100px;
text-align: center;
}
* {
box-sizing: border-box;
}
ul {
list-style-type: none;
}
body {
font-family: Verdana, sans-serif;
}
.month {
padding: 70px 25px;
width: 100%;
background: #1abc9c;
text-align: center;
}
.month ul {
margin: 0;
padding: 0;
}
.month ul li {
color: white;
font-size: 20px;
text-transform: uppercase;
letter-spacing: 3px;
}
.month .prev {
float: left;
padding-top: 10px;
}
.month .next {
float: right;
padding-top: 10px;
}
.weekdays {
margin: 0;
padding: 10px 0;
background-color: #ddd;
}
.weekdays li {
display: inline-block;
width: 13.6%;
color: #666;
text-align: center;
}
.days {
padding: 10px 0;
background: #eee;
margin: 0;
}
.days li {
list-style-type: none;
display: inline-block;
width: 13.6%;
text-align: center;
margin-bottom: 5px;
font-size: 12px;
color: #777;
}
.days li .active {
padding: 5px;
background: #1abc9c;
color: white !important
}
</style>
<h3>ex03.html - ๋ฌ๋ ฅ( ์ผ์ ๊ด๋ฆฌ )</h3>
<select id="cmbyear" onchange="changeDate()"></select>
<select id="cmbmonth" onchange="changeDate()"></select>
<select id="cmbdate"></select>
<br>
<br>
<div class="month">
<ul>
<li class="prev" onclick="changeCalendar(-1)">❮</li>
<li class="next" onclick="changeCalendar(1)">❯</li>
<li>
<span id="month">August</span><br>
<span id="year" style="font-size: 18px">2017</span>
</li>
</ul>
</div>
<ul class="weekdays">
<li>Su</li>
<li>Mo</li>
<li>Tu</li>
<li>We</li>
<li>Th</li>
<li>Fr</li>
<li>Sa</li>
</ul>
<ul class="days">
</ul>
var today = new Date();
var tYear = today.getFullYear();
var tMonth = today.getMonth();
// select 1970~2050 ๋
๋ option ์ถ๊ฐ.
// js
// jquery
for (var i = 1970; i <= 2050; i++) {
$("#cmbyear").append( $("<option></option").text( i ) );
}
// ํ์ฌ ๋
๋๋ก option ์ ํ
$("#cmbyear").val( tYear );
// select 1~12 ์ option ์ถ๊ฐ.
// js
// jquery
for (var i = 1; i <= 12; i++) {
$("#cmbmonth").append( $("<option></option").text( i ) );
}
// ํ์ฌ ์๋ก option ์ ํ
$("#cmbmonth").val( tMonth + 1 );
////////////////////////////////////////////////////////////////////////////////////
// select year, month ์ต์
์ ์ ํํ ๋ .. change ์ด๋ฒคํธ ํธ์ถ๋๋ ํจ์( ์ด๋ฒคํธ ํธ๋ค๋ฌ )
function changeDate(){
year = $("#cmbyear").val( );
month = $("#cmbmonth").val( );
console.log( year + " / " + month );
var lastDay = getLastDay(year, month);
$("#cmbdate").html(""); // ์ด๊ธฐํ
for (var i = 1; i <= lastDay; i++) {
$("#cmbdate").append( $("<option></option").text( i ) );
} // for
//
printCalendar(year, month);
}
function printCalendar(year, month){
// <span id="month">August</span><br>
// <span id="year" style="font-size: 18px">2017</span>
$("#month").text( month );
$("#year").text( year );
// <li>1</li> ~ <li>28,29,30,31</li> append()
// 1. year, month, 1 ๋ฌด์จ ์์ผ ?
var dayOfWeek = getDayOfWeek( year, month, 1 );
// 2. ๋ง์ง๋ง ๋ ์ง
var lastDay = getLastDay(year, month);
// <ul class="days">
$("ul.days").html(""); // ์ด๊ธฐํ
//๋น๊ฑฐ ๋ฃ๋ ์์
for (var i = 0; i < dayOfWeek ; i++) {
$("ul.days").append($("<li></li>"));
} // for
// 1~๋ง์ง๋ง๋ ์ง.
var outputDay ; // ์ถ๋ ฅ ๋ ์ง.
var toDay = new Date(); // ์ค๋ ๋ ์ง
for (var i = 1; i <= lastDay ; i++) {
// if( ์ถ๋ ฅ๋ ์ง == ์ค๋๋ ์ง) active ํด๋์ค ์์ฑ ์ถ๊ฐ
outputDay =new Date( year, month-1 , i );
//console.log( outputDay.toDateString() +" / " + toDay.toDateString()
// + " / " + (toDay.toDateString() == outputDay.toDateString() ))
if( toDay.toDateString() == outputDay.toDateString() ){
// <li><span class="active">10</span></li>
$("ul.days").append( "<li><span class='active'>"+i+"</span></li>" );
/*
$("ul.days").append(
$("<li></li>").append(
$("<span></span>").text(i).addClass("active")
)
)
*/
}
else{
$("ul.days").append($("<li></li>").text( i ));
}
} // for
}
function getDayOfWeek(year, month, date){
var d = new Date( year, month-1, date );
return d.getDay(); // ์ผ(0) ~ ํ (6)
}
function getLastDay(year, month){
var lastDay = 0;
var d = new Date( year, month ); // 2022.12.01 - ํ๋ฃจ = ์ผ
d.setDate(0);
// console.log( d.toDateString() ); Wed Nov 30 2022
lastDay = d.getDate();
return lastDay ;
}
changeDate(); // 2022 / 11
////////////////////////////////////////////////////////////////////////////////////
function changeCalendar( value ){
// alert( (typeof month) + "/" + (typeof value) );
month = Number(month) + value;
if( month == 0 ){
month = 12;
year--;
}else if( month == 13){
month = 1;
year++;
}
// select ๋ณ๊ฒฝ.
$("#cmbyear").val( year );
$("#cmbmonth").val( month );
changeDate(); // 1~ ๋ง์ง๋ง๋ ์ง.
// console.log( month + " / " + ( typeof month) ) ;
printCalendar(year, month);
}
์ฌ๋ผ์ด๋ฉ์ผ
<style>
*{ box-sizing: border-box;}
body{
margin: 0;
font-family: Verdana, sans-serif;
}
.slideshow-container{
max-width: 1000px;
position: relative;
margin: auto;
}
.text{
color:#2f2f2f;
font-size: 15px;
text-align: center;
padding: 8px 12px;
position: absolute;
bottom: 8px;
width:100%;
}
.numbertext{
color:#2f2f2f;
font-size: 12px;
padding: 8px 12px;
position: absolute;
top:0;
}
img{
vertical-align: middle;
}
.mySlides{
display: none;
}
</style>
<style>
.prev, .next{
position: absolute;
cursor: pointer;
top:50%;
color:white;
width:auto;
padding: 16px;
margin-top: -22px;
font-weight: bold;
font-size:18px;
border-radius: 0 3px 3px 0;
/* text-decoration: none; */
transition:0.6s ease;
}
.next{
right:0;
border-radius: 3px 0 0 3px;
}
.prev:hover, .next:hover{
background-color: rgba(0,0,0, 0.8);
}
</style>
<style>
.dots{
position: absolute;
top:10px;
width:100%;
text-align: center;
}
.dot{
cursor: pointer;
height: 15px;
width: 15px;
margin:0 2px;
background-color: #bbb;
border-radius: 50%;
display: inline-block;
transition:background-color 0.6s ease;
}
.active, .dot:hover{
background-color: #717171;
}
.fade{
animation-name:fade;
animation-duration:1.5s;
-webkit-animation-name:fade;
-webkit-animation-duration:1.5s;
}
</style>
<style>
/* ์ ๋๋ฉ์ด์
ํจ๊ณผ */
@keyframes fade{
from{ opacity: 0.4 }
to{ opacity:1}
}
@-webkit-keyframes fade{
from{ opacity: 0.4 }
to{ opacity:1}
}
</style>
<div class="slideshow-container">
<div class="mySlides fade">
<div class="numbertext">1 / 3</div>
<img src="../images/img_mountains_wide.jpg" style="width:100%" alt="" />
<div class="text">Caption One</div>
</div>
<div class="mySlides fade">
<div class="numbertext">2 / 3</div>
<img src="../images/img_nature_wide.jpg" style="width:100%" alt="" />
<div class="text">Caption Two</div>
</div>
<div class="mySlides fade">
<div class="numbertext">3 / 3</div>
<img src="../images/img_snow_wide.jpg" style="width:100%" alt="" />
<div class="text">Caption Three</div>
</div>
<a class="prev" onclick="changeSlide(-1)">❮</a>
<a class="next" onclick="changeSlide(1)">❯</a>
<div class="dots" style="text-align:center">
<span class="dot" onclick="dotSlide(0)"></span>
<span class="dot" onclick="dotSlide(1)"></span>
<span class="dot" onclick="dotSlide(2)"></span>
</div>
</div>
var slideIndex = 0;
function showSlides( sIndex ){
// js , [jQuery]
// ์ด๊ธฐํ ์์
$(".slideshow-container .mySlides").css("display", "none");
$(".dots span.dot").removeClass("active");
// sIndex
$(".slideshow-container .mySlides").eq(sIndex).css("display", "block");
$(".dots span.dot").eq(sIndex).addClass("active");
}
showSlides( slideIndex );
//////////////////////////////////////////////////////////////////
function changeSlide(value){ // -1, 1
slideIndex += value;
// 0, 1, 2
if( slideIndex == 3 ) slideIndex = 0;
else if( slideIndex == -1 ) slideIndex = 2;
showSlides( slideIndex );
}
//////////////////////////////////////////////////////////////////
function dotSlide(sIndex){
slideIndex = sIndex;
showSlides( slideIndex );
}
// ์๋ ์ฌ๋ผ์ด๋ฉ ๊ธฐ๋ฅ ์ถ๊ฐ
js ์ํ๊ฐ์ฒด( Math )
Math ๊ฐ์ฒด๋ ์์ฑ์๊ฐ ์์ต๋๋ค.
Math.์์ฑ.
// new String() + ์์ฑ์
// new Number()
// new Array()
console.log( Math.PI );
console.log( Math.abs(-100) );
console.log( Math.pow(2,3) );
// ***
console.log( Math.round( 3.1415 ) ); // 3 ๋ฐ์ฌ๋ฆผ ์์์ 1 ์๋ฆฌ
console.log( Math.ceil( 3.1415 ) ); // 3 ์ฌ๋ฆผ ์์์ 1 ์๋ฆฌ
console.log( Math.floor( 3.1415 ) ); // 3 ๋ด๋ฆผ ์์์ 1 ์๋ฆฌ
// ES6 ์ถ๊ฐ : ์ ์ ๋ถ๋ถ์ ๋ฐํ.
// Math.trunc()
console.log( Math.trunc(-4.2) +" / " + Math.floor(-4.2) ); // -4 / -5
console.log( Math.sign( -3.14) ); // 1 -1 0
// Math.max(), Math.min()
js ๋ถ์ธ(boolean)
- true / false
- js Boolean ์๋ฃํ
//console.log( 10 > 9 );
//console.log( Boolean( 10 > 9 ) ); // true Boolean() ํจ์ - ์์ ์ฐธ/๊ฑฐ์ง
// [ js boolean ์ฃผ์. ] ***
console.log( Boolean( 100 ) ); // ์์ true
console.log( Boolean( 3.14 ) ); // ์์ true
console.log( Boolean( "hello" ) ); // ๋ฌธ์์ด ์์ true
console.log( Boolean( "null" ) ); // ๋ฌธ์์ด ์์ true
// [ value ์ด ์๋ ๋ชจ๋ ๊ฒ๋ค์ false ์ด๋ค. ]
console.log( Boolean( 0 ) ); // false
console.log( Boolean( "" ) ); // false
console.log( Boolean( null ) ); // false
var name; // undefined
console.log( Boolean( name ) ); // false
console.log( Boolean( NaN ) ); // false
// var age = 0;
// var age = null;
//var age = "";
//if( age ){
//}
if( 10/"hello" ){ NaN false
}else{
}
// var x = false; // boolean
// var x = new Boolean( false ); ๊ฐ๋ฅํ์ง๋ง ์ฌ์ฉ X, object
js ์ ์ด๋ฌธ
1. if, if~else, if ~else if~ else
2. switch ~case + break
3. for / foreach
4. while(){}
do{
}while();
์ ์ : <input type="text" id="txtnum">
<br>
<p id="demo"></p>
if
$("#txtnum").keydown(function() {
if( event.keyCode == 13 ){
// ํ์ ์
๋ ฅ ์ฌํญ + ์ ์ ์
๋ ฅ. isNaN() , ์ ๊ทํํ์ /^\d+$/
if( !$("#txtnum").val().trim()){
alert("ํ์ ์
๋ ฅ!!!");
return ;
}
var n = Number( $("#txtnum").val() );
if ( n % 2 == 0) {
// ์ง์
} else {
// ํ์
}
}
});
switch
$("#txtnum").keydown(function() {
var n = Number( $("#txtnum").val() );
switch ( n % 2 ) {
case 0:
break;
default:
break;
}
while
$("#txtnum").keydown(function() {
if( event.keyCode == 13 ){
var n = Number( $("#txtnum").val() );
var content = "";
var sum = 0;
/*
for (var i = 1; i <= n; i++) {
content += i+"+";
sum += i;
} // for
*/
var i = 1;
while( i <= n ){
content += i+"+";
sum += i;
i++;
} // while
content += "=" + sum;
$("#demo").html( content );
//for ( var x in iterable) { }
//for ( var x of iterable) { }
} // if
});
for in
// 1. for in ๋ฌธ์ ๊ฐ์ฒด(๊ฐ์ฒด)์ ์์ฑ์ ๋ฐ๋ณตํ๋ ๋ฐ๋ณต๋ฌธ
// 2. ํ์
// for( let prop in object){
//}
var m = [ 3,5,2,4,1];
// console.log( typeof m ); // ๋ฐฐ์ด๋ ํ์
์ object ์ด๋ค.
// x = 0,1,2,3,4 index
for ( var idx in m) {
// console.log( idx ) ;
console.log( m[idx] );
}
//
Array.forEach( function (elt, index, array){
} )
// js object
var person = {
// ์์ฑ๋ช
:์์ฑ๊ฐ
name:"admin",
age:20
};
// person.name
// person["name"]
for ( var p in person) { // object
console.log( person[p] );
// for in๋ฌธ์์์ person.idx๋ ์ ์๋๋์??
// console.log( person.p);
// console.log( typeof p ); // string
}
for of
[js ์ ์ด๋ฌธ( for of)]
- ES6(2015) ์๋ก ์ถ๊ฐ๋ ๋ฌธ
- IE ์ง์๋์ง ์์์.
- ๋ฐ๋ณต ๊ฐ๋ฅํ ๊ฐ์ฒด์ ๊ฐ์ ๋ฐ๋ณตํ๋ ๋ฌธ
(Arrays, Strings, [ Maps, NodeLists ]X ๋ฐ๋ณต๊ฐ๋ฅํ ๋ฐ์ดํฐ ๊ตฌ์กฐ. )
var m = [3,5,2,4,1];
for ( var n of m) {
console.log( n );
}
var msg = "hello world!";
for (var i = 0; i < msg.length; i++) {
console.log( msg.charAt(i) );
} // for
for (let ch of msg) {
console.log("["+ch + "]")
}
<style>
.container{
width: 500px;
}
.collapsible{
background-color: #777;
color:white;
cursor: pointer;
padding: 18px;
width: 100%;
border: none;
text-align: left;
outline:none;
font-size: 15px;
}
/* ::๊ฐ์ ์์ ์ ํ์*/
.collapsible::after{
content:'\002B'; /* + */
color:white;
float: right;
font-weight: bold;
margin-left: 5px;
}
.collapsible:hover , .active{
background-color: #555;
}
.content{
padding: 0 18px;
background-color: #f1f1f1;
max-height: 0; /* ์ค๋ฒํ๋ก์ฐ๊ฐ ๋ฐ์.. */
overflow: hidden; /* ์จ๊ธฐ๊ธฐ */
transition:max-height 0.2s ease-out;
}
.active::after{
content:'\2212'; /* - */
}
</style>
<div class="container">
<button class="collapsible">Section 1</button>
<div class="content">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Nulla iure aliquam soluta minima impedit ratione laboriosam autem omnis. Doloribus eius incidunt totam iure deleniti a officia blanditiis rem recusandae officiis.</div>
<button class="collapsible">Section 2</button>
<div class="content">
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Nulla iure aliquam soluta minima impedit ratione laboriosam autem omnis. Doloribus eius incidunt totam iure deleniti a officia blanditiis rem recusandae officiis.
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Nulla iure aliquam soluta minima impedit ratione laboriosam autem omnis. Doloribus eius incidunt totam iure deleniti a officia blanditiis rem recusandae officiis.
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Nulla iure aliquam soluta minima impedit ratione laboriosam autem omnis. Doloribus eius incidunt totam iure deleniti a officia blanditiis rem recusandae officiis.
</div>
<button class="collapsible">Section 3</button>
<div class="content">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Nulla iure aliquam soluta minima impedit ratione laboriosam autem omnis. Doloribus eius incidunt totam iure deleniti a officia blanditiis rem recusandae officiis.</div>
</div>
// js , [jquery]
$(".collapsible").click(function() {
$(this).toggleClass("active");
// ํด๋ฆญ๋ ๋ฒํผ ๋ค์ <div class="content">
if( $(this).next().css("max-height") != "0px" ){
$(this).next().css("max-height", "0px" );
}else{
$(this).next().css("max-height", $(this).next().prop("scrollHeight")+"px" );
}
});
* toggleclass : ํด๋์ค์์ฑ ์์ผ๋ฉด ์ ๊ฑฐํ๊ณ ์์ผ๋ฉด ์ค๋ค๋ ๋ป
* ํด๋ฆญ๋ ๋ฒํผ ๋ค ๊ธ ์ฐพ์์์ (next()) max-height์์ฑ์ ์ค
0px์๋๋ฉด -> 0px
0px์ด๋ฉด -> max height ์์ฑ ์ฃผ๋๋ฐ, ๊ทธ ๋ค ์์ฑ๊ฐ(scrollheight) ์ฝ์ด์์ px๋จ์ ๋ถ์ฌ์ค
(scrollheight ์๋ง ๊ธธ๊ฒ ๋ด๋ฆฌ๋ ์์ฑ)
์ต๊ทผ๋๊ธ