Notice
Recent Posts
Recent Comments
ยซ   2024/12   ยป
์ผ ์›” ํ™” ์ˆ˜ ๋ชฉ ๊ธˆ ํ† 
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31
Archives
Today
In Total
๊ด€๋ฆฌ ๋ฉ”๋‰ด

A Joyful AI Research Journey๐ŸŒณ๐Ÿ˜Š

[19] 230125 Ch. 12 jQUERY, Ajax, JSON: 1. jQuery, 2. ์ฒซ ๋ฒˆ์งธ jQuery ํ”„๋กœ๊ทธ๋žจ, 3. jQuery ๋ฌธ์žฅ์˜ ๊ตฌ์กฐ, 4. jQuery๋ฅผ ์ด์šฉํ•œ ์ด๋ฒคํŠธ ์ฒ˜๋ฆฌ · 5. ์• ๋‹ˆ๋ฉ”์ด์…˜ ํšจ๊ณผ [K-๋””์ง€ํ„ธ ํŠธ๋ ˆ์ด๋‹ 19์ผ] ๋ณธ๋ฌธ

๐ŸŒณBootcamp Revision 2023โœจ/JavaScript, jQuery, Ajax, JSON

[19] 230125 Ch. 12 jQUERY, Ajax, JSON: 1. jQuery, 2. ์ฒซ ๋ฒˆ์งธ jQuery ํ”„๋กœ๊ทธ๋žจ, 3. jQuery ๋ฌธ์žฅ์˜ ๊ตฌ์กฐ, 4. jQuery๋ฅผ ์ด์šฉํ•œ ์ด๋ฒคํŠธ ์ฒ˜๋ฆฌ · 5. ์• ๋‹ˆ๋ฉ”์ด์…˜ ํšจ๊ณผ [K-๋””์ง€ํ„ธ ํŠธ๋ ˆ์ด๋‹ 19์ผ]

yjyuwisely 2023. 1. 25. 12:50

230125 Wed 19th class

Ch. 12 jQUERY, Ajax, JSON
์ง„๋„: p. 452 ~ (๊ต์žฌ: HTML5 + CSS3 + JavaScript๋กœ ๋ฐฐ์šฐ๋Š” ์›นํ”„๋กœ๊ทธ๋ž˜๋ฐ ๊ธฐ์ดˆ, ์ €์ž: ์ฒœ์ธ๊ตญ)

 

HTML5+CSS3+JavaScript๋กœ ๋ฐฐ์šฐ๋Š” ์›นํ”„๋กœ๊ทธ๋ž˜๋ฐ ๊ธฐ์ดˆ | ์ฒœ์ธ๊ตญ - ๊ต๋ณด๋ฌธ๊ณ 

HTML5+CSS3+JavaScript๋กœ ๋ฐฐ์šฐ๋Š” ์›นํ”„๋กœ๊ทธ๋ž˜๋ฐ ๊ธฐ์ดˆ | ์›นํ”„๋กœ๊ทธ๋ž˜๋ฐ ์ดˆ๋ณด์ž๋„ ์‰ฝ๊ฒŒ ๋ฐฐ์šฐ๋Š” ์›น ๊ฐœ๋ฐœ ์ง€์นจ์„œ!์ด ์ฑ…์€ ์›นํ”„๋กœ๊ทธ๋ž˜๋ฐ์„ ์ฒ˜์Œ ๋ฐฐ์šฐ๋Š” ์ดˆ๋ณด์ž๋“ค์„ ์œ„ํ•ด ๊ธฐ์ดˆ๋ถ€ํ„ฐ ์ฐจ๊ทผ์ฐจ๊ทผ ์„ค๋ช…ํ•œ๋‹ค. 1~3์žฅ์—

product.kyobobook.co.kr


์˜ค๋Š˜ ๋ฐฐ์šด ๊ฒƒ ์ค‘ ๊ธฐ์–ตํ•  ๊ฒƒ์„ ์ •๋ฆฌํ–ˆ๋‹ค.


์ง€๋‚œ ์ˆ˜์—… ๋•Œ ๋ฐฐ์šด ๊ฒƒ ์ค‘ ๋‹ค์‹œ ๊ธฐ์–ตํ•  ๊ฒƒ

display: none; is commonly used with JavaScript to hide and show elements without deleting and recreating them. The <script> element uses display: none; as default. 

2023.01.05 - [1. Revision 2023/CSS3] - *[7] 230105 Ch. 6 CSS ๋ ˆ์ด์•„์›ƒ๊ณผ ์• ๋‹ˆ๋ฉ”์ด์…˜(1): ๋ ˆ์ด์•„์›ƒ์˜ ๊ธฐ์ดˆ, ์š”์†Œ ์œ„์น˜ ์ •ํ•˜๊ธฐ, (์š”์†Œ) · ์˜๋ฏธ์  ์š”์†Œ๋ฅผ ์ด์šฉํ•œ ๋ ˆ์ด์•„์›ƒ, ํšจ๊ณผ, CSS3 ๋ณ€ํ™˜ · 3์ฐจ์› ๋ณ€ํ™˜ · ์• ๋‹ˆ๋ฉ”์ด์…˜

 

์ฐธ๊ณ  p. 196 

display:block /*๋ธ”๋ก(block)*/
display:inline /*์ธ๋ผ์ธ(inline)*/
display:none /*์—†๋Š” ๊ฒƒ์œผ๋กœ ๊ฐ„์ฃผ๋จ*/
display:hidden /*ํ™”๋ฉด์—์„œ ๊ฐ์ถฐ์ง*/

display: none: ๋ฌธ์„œ์˜ ํ๋ฆ„์—์„œ ํ•ด๋‹น ์š”์†Œ๋ฅผ ์™„์ „ํžˆ ๋ฐฐ์ œํ•˜๊ณ ์ž ํ•  ๋•Œ ์‚ฌ์šฉ๋œ๋‹ค.
display: hidden: ๋ฌธ์„œ์˜ ํ๋ฆ„์—์„œ ์š”์†Œ๊ฐ€ ์ œ๊ฑฐ๋˜์ง€ ์•Š์ง€๋งŒ ๋ณด์ด์ง€๋Š” ์•Š๋Š” ์ƒํƒœ์ด๋‹ค.
์ฐธ๊ณ ํ•˜๊ธฐ: https://www.w3schools.com/css/css_display_visibility.asp


Ch. 12 jQUERY, Ajax, JSON

์ฑ…์˜ ๋ชฉ์ฐจ
-jQuery
-์ฒซ ๋ฒˆ์งธ jQuery ํ”„๋กœ๊ทธ๋žจ
-jQuery ๋ฌธ์žฅ์˜ ๊ตฌ์กฐ
-jQuery๋ฅผ ์ด์šฉํ•œ ์ด๋ฒคํŠธ ์ฒ˜๋ฆฌ
-jQuery๋ฅผ ์ด์šฉํ•œ ์• ๋‹ˆ๋ฉ”์ด์…˜ ํšจ๊ณผ
-jQuery๋ฅผ ์ด์šฉํ•œ DOM ๋ณ€๊ฒฝ
-jQuery๋ฅผ ์ด์šฉํ•œ CSS ์กฐ์ž‘
-Ajax ๊ฐœ์š”
-jQuery๋ฅผ ์ด์šฉํ•˜์—ฌ Ajax ์‚ฌ์šฉํ•˜๊ธฐ
-JSON

1. jQuery p. 452

์ผ์ข…์˜ ์ž๋ฐ” ์Šคํฌ๋ฆฝํŠธ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ
jQuery๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ์ž๋ฐ” ์Šคํฌ๋ฆฝํŠธ ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์–‘์„ ์ƒ๋‹นํžˆ ์ค„์ผ ์ˆ˜ ์žˆ๋‹ค.
๋ฐฐ์šฐ๊ธฐ ์‰ฝ๋‹ค.
๋ฌด๋ฃŒ์ด๋‹ค. ์„ค์น˜ ๊ณผ์ •๋„ ํ•„์š” ์—†์ด ๊ทธ๋ƒฅ ํ•œ ์ค„๋งŒ ์†Œ์Šค์— ์ถ”๊ฐ€ํ•˜๋ฉด ๋œ๋‹ค.

์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ jQuery
id๊ฐ€ myPara์ธ ์š”์†Œ๋ฅผ ์ฐพ์•„์„œ ๋‚ด์šฉ์„ ๋ณ€๊ฒฝํ•œ๋‹ค.
document.getElementsById("myPara").innerHTML = "์•ˆ๋…•ํ•˜์„ธ์š”?" $("#myPara").html("์•ˆ๋…•ํ•˜์„ธ์š”?")

 

1.1 jQuery ์‚ฌ์šฉ ๋ฐฉ๋ฒ•

๋‘˜ ์ค‘ ํ•˜๋‚˜๋ฅผ ์„ ํƒํ•œ๋‹ค.

1) jQuery์—์„œ jQuery ํŒŒ์ผ์„ ๋‹ค์šดํ•˜๋Š” ๋ฐฉ๋ฒ•
http://www.jquery.com์—์„œ ๋‹ค์šด๋กœ๋“œ
ํฌ๋กฌ์˜ ๊ฒฝ์šฐ ๋‹ค๋ฅธ ์ด๋ฆ„์œผ๋กœ ์ €์žฅ์œผ๋กœ ๋‹ค์šด๋ฐ›๋Š”๋‹ค. 

๋‹ค์šด๋กœ๋“œ ๋ฒ„์ „์—๋„ 2๊ฐ€์ง€๊ฐ€ ์กด์žฌํ•˜๋Š”๋ฐ compressed(์••์ถ•) ๋ฒ„์ „๊ณผ uncompressed ๋ฒ„์ „์ด ์žˆ๋‹ค.
compressed ๋ฒ„์ „์€ ๊ณต๋ฐฑ์ด ๋ชจ๋‘ ์ œ๊ฑฐ๋œ ๋ฒ„์ „์ด๋ฉฐ uncompressed ๋ฒ„์ „์€ ๊ณต๋ฐฑ์ด ์œ ์ง€๋˜์–ด ์žˆ๋Š” ๋ฒ„์ „์ด๋‹ค.
๋”ฐ๋ผ์„œ uncompressed ๋ฒ„์ „์˜ ์šฉ๋Ÿ‰์ด ์•ฝ 3๋ฐฐ ์ •๋„ ์ปค์„œ ์†๋„์—๋Š” ๋ถˆ๋ฆฌํ•˜๋‚˜ ๊ฐœ๋ฐœ/๋””๋ฒ„๊น… ์ž‘์—… ์‹œ์—๋Š” ์œ ์šฉํ•˜๊ฒŒ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค.

๋‹ค์šด ๋ฐ›์•„์„œ js ํŒŒ์ผ์— ๋ณต์‚ฌํ•ด์„œ ๋ถ™์—ฌ๋„ฃ๋Š”๋‹ค.

์•„๋ž˜์ฒ˜๋Ÿผ ์‚ฌ์šฉํ•œ๋‹ค. 

<script type="text/javascript" src="js/jquery-3.6.3.js"></script>

 

2) ์‹คํ–‰์‹œ๋งˆ๋‹ค ๊ตฌ๊ธ€์ด๋‚˜ ๋งˆ์ดํฌ๋กœ์†Œํ”„ํŠธ์—์„œ jQuery ํŒŒ์ผ์„ ํฌํ•จํ•˜๋Š” ๋ฐฉ๋ฒ•
- ๊ณต๊ฐœ ์„œ๋ฒ„๋กœ๋ถ€ํ„ฐ ๋„คํŠธ์›Œํฌ๋ฅผ ํ†ตํ•˜์—ฌ ์›นํŽ˜์ด์ง€๋ฅผ ์‹คํ–‰ํ•  ๋•Œ๋งˆ๋‹ค ๋‹ค์šด๋กœ๋“œ๋ฐ›์„ ์ˆ˜๋„ ์žˆ๋‹ค. 
- 1.10.1๋ฒ„์ „

<script type="text/javascript" src="https://code.jquery.com/jquery-3.6.3.min.js"></script>

 

2. ์ฒซ ๋ฒˆ์งธ jQuery ํ”„๋กœ๊ทธ๋žจ

https://jquery.com/download/์˜ Downloading jQuery using Bower์˜ ๋‘๋ฒˆ์งธ ์ฝ”๋“œ๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค.

<head>
<script src="http://code.jquery.com/jquery-1.10.1.min.js></script>
</head>

3. jQuery ๋ฌธ์žฅ์˜ ๊ตฌ์กฐ p. 2567

jQuery ๋ฌธ์žฅ์˜ ์˜๋ฏธ๋Š” HTML ์š”์†Œ๋ฅผ ์„ ํƒํ•˜์—ฌ (๋˜๋Š” ์ฐพ์•„์„œ), ์„ ํƒ๋œ ์š”์†Œ์— ์–ด๋–ค ๋™์ž‘(action)์„ ์‹œํ‚ค๋Š” ๊ฒƒ์ด๋‹ค.

$(selector).action();

$: jQuery๋ผ๋Š” ์˜๋ฏธ์ด๋‹ค.
selector: ์„ ํƒ์ž (CSS์„ ํƒ์ž์™€ ๋˜‘๊ฐ™๋‹ค. id(#), ํด๋ž˜์Šค(.) ๋“ฑ)

2023.01.03 - [1. Revision 2023/CSS3] - [5] 230103 Ch4 CSS3 ์Šคํƒ€์ผ ์‹œํŠธ ๊ธฐ์ดˆ

$(selector).: ์„ ํƒ์ž์— ์˜ํ•˜์—ฌ ์„ ํƒ๋œ ์š”์†Œ
action(): ์„ ํƒ๋œ ์š”์†Œ์˜ ํ•จ์ˆ˜ ํ˜ธ์ถœ

ex) $("h1")์€ ํŽ˜์ด์ง€์— ์žˆ๋Š” ๋ชจ๋“  <h1>์š”์†Œ๋ฅผ ์ฐพ์•„์„œ ๊ฐ–๋‹ค ๋‹ฌ๋ผ๋Š” ์˜๋ฏธ์ด๋‹ค.


3.1 ์„ ํƒ์ž

1) ํƒ€์ž… ์„ ํƒ์ž

์š”์†Œ์˜ ์ด๋ฆ„์„ ์ ์–ด์„œ ์š”์†Œ๋ฅผ ์„ ํƒํ•œ๋‹ค. 

<body>
<p> ์ด๊ฒƒ์€ ๋ฌธ๋‹จ์ž…๋‹ˆ๋‹ค. </p>
<p> ์ด๊ฒƒ์€ ๋ฌธ๋‹จ์ž…๋‹ˆ๋‹ค. </p>
</body>

์˜ˆ๋ฅผ ๋“ค์–ด <p>๋ผ๊ณ  ํ•˜๋ฉด ํŽ˜์ด์ง€ ์•ˆ์˜ ๋ชจ๋“  <p> ์š”์†Œ๊ฐ€ ์„ ํƒ๋œ๋‹ค. 

$("p").hide();

 

๋ชจ๋“  <p> ์š”์†Œ๋ฅผ ์ฐพ์•„์„œ ํ™”๋ฉด์— ํ‘œ์‹œํ•œ๋‹ค.

$("p").show()

 

2) .class ์„ ํƒ์ž

์š”์†Œ๋ฅผ ์ •์˜ํ•  ๋•Œ ์š”์†Œ์— ํด๋ž˜์Šค ์ด๋ฆ„์„ ์ค„ ์ˆ˜ ์žˆ๋‹ค. 

<body>
<h1> ์ œ๋ชฉ </h1>
<p class="menu">1. ๊ตฌ์ž… </p>
<p> 2. ๊ฒฐ์ œ </p>
</body>

.class์™€ ๊ฐ™์€ ํ˜•์‹์œผ๋กœ ํŠน์ •ํ•œ ํด๋ž˜์Šค์— ์ด๋ฆ„์„ ๊ฐ€์ง€๋Š” ์š”์†Œ๋ฅผ ์„ ํƒํ•  ์ˆ˜ ์žˆ๋‹ค.

$(".menu").slideup();

 

class=group1์ธ ์š”์†Œ๋ฅผ ์Šฌ๋ผ์ด๋“œ์—… ๋ฐฉ์‹์œผ๋กœ ํ‘œ์‹œํ•œ๋‹ค.

$(".group1").slideup()

 

3) #id ์„ ํƒ์ž

์š”์†Œ๋ฅผ ์ •์˜ํ•  ๋•Œ ์š”์†Œ์— id ์†์„ฑ์„ ๋ถ€์—ฌํ•  ์ˆ˜ ์žˆ๋‹ค.

<body>
<h1> ์ œ๋ชฉ <h1>
<p> ๋ฌธ๋‹จ์ž…๋‹ˆ๋‹ค. </p>
<p id="check"> ๋ฌธ๋‹จ์ž…๋‹ˆ๋‹ค. </p>
</body>

#id์™€ ๊ฐ™์€ ํ˜•์‹์œผ๋กœ ํŠน์ •ํ•œ ์•„์ด๋””๋ฅผ ๊ฐ–๋Š” ์š”์†Œ๋ฅผ ์„ ํƒํ•  ์ˆ˜ ์žˆ๋‹ค.

$("#check").show();



id=id9
์ธ ์š”์†Œ๋ฅผ ํ™”๋ฉด์—์„œ ๊ฐ์ถ˜๋‹ค.

$("#id9").hide()

 

4) ๊ทธ ์™ธ์˜ ์„ ํƒ์ž

ํ˜•์‹                                   ์„ค๋ช…
$("*") ๋ชจ๋“  ์š”์†Œ๋ฅผ ์„ ํƒํ•œ๋‹ค.
$(this) ์‚ฌ์šฉ์ž๊ฐ€ ์„ ํƒํ•œ, ํ˜„์žฌ ์š”์†Œ๋ฅผ ์„ ํƒํ•œ๋‹ค.
$("p.myClass")  <p> ์š”์†Œ ์ค‘์—์„œ class="myClass"์ธ ์š”์†Œ
$("p:first") ์ฒซ๋ฒˆ์งธ <p> ์š”์†Œ 
$("p:last") ๋งˆ์ง€๋ง‰ <p> ์š”์†Œ 
$("div span") <div> ์•ˆ์— ํฌํ•จ๋œ <span> ์š”์†Œ
$(":button") ๋ฒ„ํŠผ๊ณผ ๋ฒ„ํŠผ ํƒ€์ž… ์š”์†Œ๋ฅผ ๋ชจ๋‘ ์„ ํƒ,
์ฆ‰ <button></button> ํ˜น์€ <input type="button"/>์ด ๋ชจ๋‘ ์„ ํƒ๋œ๋‹ค.

$(this) is a jQuery wrapper around that element that enables usage of jQuery methods. jQuery calls the callback using apply() to bind this . Calling jQuery a second time (which is a mistake) on the result of $(this) returns an new jQuery object based on the same selector as the first one.


3.2 ์ผ๋ฐ˜์ ์ธ jQuery ๊ตฌ์กฐ p. 459

์•„๋ž˜ ๊ตฌ์กฐ๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ์ด์œ ๋Š” ๋ฌธ์„œ๊ฐ€ ์™„์ „ํžˆ ๋กœ๋“œ๋˜๊ธฐ ์ „์— jQuery ์ฝ”๋“œ๊ฐ€ ์‹คํ–‰ํ•˜๋Š” ๊ฒƒ์„ ๋ฐฉ์ง€ํ•˜๊ธฐ ์œ„ํ•ด์„œ์ด๋‹ค. ๋งŒ์•ฝ ๋ฌธ์„œ๊ฐ€ ์™„์ „ํžˆ ๋กœ๋“œ๋˜์ง€ ์•Š์€ ์ƒํƒœ์—์„œ jQuery ๋ฉ”์„œ๋“œ๊ฐ€ ์‹คํ–‰๋˜๋ฉด ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ•œ๋‹ค. 

$(document).ready( function(){

// DOM์ด ๋กœ๋”ฉ๋˜์–ด์„œ ์ค€๋น„๊ฐ€ ๋˜๋ฉด ์ž‘์—…์„ ์‹œ์ž‘ํ•œ๋‹ค.
// ๊ตฌ์ฒด์ ์œผ๋กœ jQuery ๋ฉ”์„œ๋“œ๋“ค์„ ํ˜ธ์ถœํ•œ๋‹ค.

});

$(document): DOM์„ ์˜๋ฏธํ•œ๋‹ค. HTML ๋ฌธ์„œ ์ „์ฒด๋ฅผ ์„ ํƒํ•œ๋‹ค. 
ready: '์ค€๋น„๊ฐ€ ๋˜๋ฉด'์ด๋ผ๋Š” event์ด๋‹ค.
function(){;: ํ•จ์ˆ˜ ์ •์˜

๊ธฐ๋ณธ์ ์ธ ๊ตฌ์กฐ์ด๋‹ค.

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>BASIC</title>
<style>

</style>
<script type="text/javascript" src="https://code.jquery.com/jquery-3.6.3.min.js"></script>
<script>
$(document).ready(function(){

});
</script>
</head>
<body>

</body>
</html>

 

DOM์„ ์ฝ์€ ํ›„ ํ•จ์ˆ˜๋ฅผ ์‹คํ–‰ํ•œ๋‹ค๋Š” ์˜๋ฏธ์ด๋‹ค. 

์•„๋ž˜์ฒ˜๋Ÿผ jQuery๋ฅผ ๋จผ์ € ์„ ์–ธํ•œ ํ›„ <script>์„ ์‚ฌ์šฉํ•œ๋‹ค.

<script type="text/javascript" src="https://code.jquery.com/jquery-3.6.3.min.js"></script>
</head>
<body>
<script> 
//$(document): html๋ฌธ์„œ ์ „์ฒด๋ฅผ ์„ ํƒํ•œ๋‹ค. 
$(document).ready(function (){
	
});
</script>
</body>
</html>

4. jQuery๋ฅผ ์ด์šฉํ•œ ์ด๋ฒคํŠธ ์ฒ˜๋ฆฌ p.460

jQuery๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ์ด๋ฒคํŠธ ์ฒ˜๋ฆฌ๋ฅผ ์‰ฝ๊ฒŒ ํ•  ์ˆ˜ ์žˆ๋‹ค.
์˜ˆ๋ฅผ ๋“ค์–ด ๋‹ค์Œ๊ณผ ๊ฐ™์€ ๊ฒƒ์ด ์ด๋ฒคํŠธ์ด๋‹ค.

- ์š”์†Œ๋ฅผ ๋งˆ์šฐ์Šค๋กœ ํด๋ฆญํ•œ๋‹ค. → click ์ด๋ฒคํŠธ ๋ฐœ์ƒ
- ํ‚ค๋ณด๋“œ์˜ ํ‚ค๋ฅผ ๋ˆ„๋ฅธ๋‹ค. → keypress ์ด๋ฒคํŠธ ๋ฐœ์ƒ
- ์‚ฌ์šฉ์ž๊ฐ€ ์ž…๋ ฅํ•„๋“œ์— ๊ฐ’์„ ์ž…๋ ฅํ•œ๋‹ค. → change ์ด๋ฒคํŠธ ๋ฐœ์ƒ

์ด๋ฒคํŠธ์˜ ์˜ˆ์ œ)

<html>
<head>
<script>
		function add(){
        
        }
</script>
</head>
<body>
<input type="button" value="ํ™•์ธ" onclick="add()">
</body>
</html>

 

4.1 ์ด๋ฒคํŠธ์˜ ์ข…๋ฅ˜

์•„๋ž˜๋Š” ์ค‘์š”ํ•œ ์ด๋ฒคํŠธ๋“ค์ด๋‹ค.

ํ‚ค๋ณด๋“œ  ๋งˆ์šฐ์Šค
  • keypress
  • keydown
  • keyup
  • click
  • dblclick
  • mouseenter
  • mouseleave
ํผ ์ฐฝ
  • submit
  • change
  • focus
  • blur
  • resize
  • load
  • unload
  • scroll

 

4.2 jQuery ์ด๋ฒคํŠธ ๋ฉ”์„œ๋“œ์˜ ๊ตฌ๋ฌธ

 

์˜ˆ์ œ) ๋ฒ„ํŠผ์„ ํด๋ฆญํ•˜๋ฉด ๋นจ๊ฐ„ ์ƒ์ž๊ฐ€ ๋‚˜์˜จ๋‹ค.

display: none; is commonly used with JavaScript to hide and show elements without deleting and recreating them. The <script> element uses display: none; as default. 

<script src="https://code.jquery.com/jquery-3.6.3.min.js"></script>
<script>
$(document).ready(function(){
	// "๋ˆŒ๋Ÿฌ๋ณด์„ธ์š”"๋ผ๋Š” ๋ฒ„ํŠผ์„ ํด๋ฆญํ•˜๋ฉด
	//$("#button1").on("click", function(){ // ๊ธฐ๋ณธ์ ์ธ ์ด๋ฒคํŠธ ํ•ธ๋“ค๋ง
	$("#button1").click(function(){ // ์œ„ ๊ธฐ๋ณธ์ ์ธ ์ด๋ฒคํŠธ ํ•ธ๋“ค๋ง ๋ณ€ํ˜•.
	//	alert("์—ฐ๊ฒฐ๋จ.");
	$("#box").show(); //show: <div>๋ฅผ ๋ณด์—ฌ์ค€๋‹ค.
	})
});
</script>
<style>
#box{ background-color: red; width: 100px; height: 100px; display: none;}
</style>
</head>
<body>
<input type="button" id="button1" value="๋ˆŒ๋Ÿฌ๋ณด์„ธ์š”." onclick="click()">
<div id=box></div>
</body>

๊ฒฐ๊ณผ)

4.3 ์ด๋ฒคํŠธ ๋“ฑ๋ก ๋ฐฉ๋ฒ•

์ •์‹ ๋ฐฉ๋ฒ•: ์›๋ž˜ ์ด๋ ‡๊ฒŒ ํ•ด์•ผ ๋œ๋‹ค. ๋™์ ์œผ๋กœ ์ถ”๊ฐ€๋œ ์š”์†Œ์—์„œ๋Š” ์ •์‹ ๋ฐฉ๋ฒ•์„ ์‚ฌ์šฉํ•œ๋‹ค. 

$("#div1").on('click', function()
{
		...
});

๋‹จ์ถ• ๋ฉ”์„œ๋“œ ๋ฐฉ๋ฒ•: 99%์˜ ๊ฐœ๋ฐœ์ž๋Š” ์ด๋ ‡๊ฒŒ ์‚ฌ์šฉํ•œ๋‹ค. ์ด๋ฏธ DOM ํŠธ๋ฆฌ ์•ˆ์— ์š”์†Œ๊ฐ€ ์ƒ์„ฑ๋˜์–ด ์žˆ์„ ๋•Œ๋งŒ ๊ฐ€๋Šฅํ•˜๋‹ค. 

$("#div1").click( function(){
		...
});

 

4.4 ๋งˆ์šฐ์Šค ์ด๋ฒคํŠธ p. 462

mouseenter: ์š”์†Œ ์•ˆ์œผ๋กœ ๋งˆ์šฐ์Šค๊ฐ€ ์ง„์ž…ํ•œ๋‹ค.
mouseleave: ๋งˆ์šฐ์Šค๊ฐ€ ์š”์†Œ๋ฅผ ๋น ์ ธ๋‚˜๊ฐ„๋‹ค.
mousedown: ์™ผ์ชฝ ๋งˆ์šฐ์Šค ๋ฒ„ํŠผ์ด ๋ˆŒ๋ ค์ง€๋ฉด ๋ฐœ์ƒํ•œ๋‹ค.
mouseup: ์™ผ์ชฝ ๋งˆ์šฐ์Šค ๋ฒ„ํŠผ์ด ๋–ผ์–ด์ง€๋ฉด ๋ฐœ์ƒํ•œ๋‹ค.
mouseover: ๋งˆ์šฐ์Šค๊ฐ€ ํŠน์ • ์š”์†Œ ์œ„์— ์žˆ์œผ๋ฉด ๋ฐœ์ƒํ•œ๋‹ค.

์˜ˆ์ œ) <div> ํƒœ๊ทธ๋กœ ์‚ฌ๊ฐํ˜•์„ ๋งŒ๋“ค๊ณ  ๋งˆ์šฐ์Šค ์ปค์„œ๊ฐ€ ์‚ฌ๊ฐํ˜• ์•ˆ์„ ๋„˜์–ด์˜ค๋ฉด ๋ณ€์ˆ˜์˜ ๊ฐ’์„ ์ฆ๊ฐ€์‹œ์ผœ ํ™”๋ฉด์— ์ถœ๋ ฅํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ

<head>
<meta charset="UTF-8">
<title>mouse</title>
<!-- ์‚ฌ๊ฐํ˜•์˜ ์Šคํƒ€์ผ ์ •์˜ -->
<style>div.out{width:200px;height:60px;background-color:yellow;}</style>
<!-- jQuery ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ์ฐธ์กฐ -->
<script src="https://code.jquery.com/jquery-3.6.3.min.js"></script>
</head>

<body>
	<div class = "out">
		<p> ๋งˆ์šฐ์Šค๋ฅผ ์—ฌ๊ธฐ๋กœ ์›€์ง์ด์„ธ์š”. </p>
		<p> 0 </p>
	</div>
<script>
	var i = 0;
	//class๋ช…์ด out์ธ div์— ๋งˆ์šฐ์Šค๋ฅผ ์˜ฌ๋ ธ์„ ๋•Œ(mouseover) ์ด๋ฒคํŠธ ์ ์šฉ
	//(=out ํด๋ž˜์Šค์˜ <div>์—์„œ mouseover ์ด๋ฒคํŠธ๊ฐ€ ๋ฐœ์ƒํ•˜๋ฉด)
	$("div.out").mouseover(function(){
		//document.getElementsTagName("p")[0].innerHTML="mouse over"; ์ž๋ฐ”์ŠคํŠธ๋ฆฝํŠธ
		//์ฒซ ๋ฒˆ์งธ <p>์š”์†Œ์˜ ๋‚ด์šฉ์„ "mouse over"๋กœ ๋ณ€๊ฒฝํ•œ๋‹ค.
		$("p:first").text("mouse over");
		//๋งˆ์ง€๋ง‰ <p>์š”์†Œ์— ์ฆ๊ฐ€๋ณ€ ๋ณ€์ˆ˜ i์˜ ๊ฐ’์„ ์ถœ๋ ฅํ•œ๋‹ค.
		$("p:last").text(++i);
	})
</script>
</body>

๊ฒฐ๊ณผ)

 

4.5 focus์™€ blur ์ด๋ฒคํŠธ p. 464

focus (์ปค์„œ๊ฐ€ ๊นœ๋นก๊ฑฐ๋ฆผ) ์ด๋ฒคํŠธ๋Š” ์ž…๋ ฅ ํ•„๋“œ๊ฐ€ ํ‚ค๋ณด๋“œ ํฌ์ปค์Šค๋ฅผ ์–ป์œผ๋ฉด ๋ฐœ์ƒํ•œ๋‹ค. 
๋ฐ˜๋Œ€๋กœ ์ž…๋ ฅ ํ•„๋“œ๊ฐ€ ํ‚ค๋ณด๋“œ ํฌ์ปค์Šค๋ฅผ ์žƒ์œผ๋ฉด blur (์ปค์„œ ์žƒ์Œ)์ด๋ฒคํŠธ๊ฐ€ ๋ฐœ์ƒํ•œ๋‹ค.
ex) blur ์ด๋ฒคํŠธ: NAVER ํšŒ์›๊ฐ€์ž…์˜ ๊ฒฝ์šฐ, blur ์ด๋ฒคํŠธ๊ฐ€ ๋ฐœ์ƒํ•  ๋•Œ ์•„์ด๋”” ๋ฐ‘์— ๋นจ๊ฐ„์ƒ‰ ํฐํŠธ๋กœ 'ํ•„์ˆ˜ ์ •๋ณด์ž…๋‹ˆ๋‹ค'๊ฐ€ ๋œฌ๋‹ค. 

์˜ˆ์ œ)  ์ž…๋ ฅ ํ•„๋“œ๋ฅผ ๋งŒ๋“ค๊ณ  ํฌ์ปค์Šค๋ฅผ ์–ป์œผ๋ฉด ์ž…๋ ฅ ํ•„๋“œ์˜ ๋ฐฐ๊ฒฝ์ƒ‰์„ ๋…ธ๋ž€์ƒ‰์œผ๋กœ ๋ณ€๊ฒฝํ•ด๋ณด๊ณ  ํฌ์ปค์Šค๋ฅผ ์žƒ์œผ๋ฉด ํฐ์ƒ‰์œผ๋กœ ๋ณ€๊ฒฝํ•ด ๋ณด์ž.
this: ์œ„์˜ input์„ ๋”ฐ๋ผ๊ฐ„๋‹ค. ์œ„์˜ ๊ฒƒ์„ ์ด์–ด์„œ ์ ์šฉํ•œ๋‹ค.

<head>
<meta charset="UTF-8">
<title>focus and blur p.464</title>
<script type="text/javascript" src="https://code.jquery.com/jquery-3.6.3.min.js"></script>
<script>
$(document).ready(function(){
	//inputํƒœ๊ทธ์˜ ์ปค์„œ(ํฌ์ปค์Šค)๋ฅผ ์–ป์œผ๋ฉด inputํƒœ๊ทธ์˜ ๋ฐฐ๊ฒฝ์ƒ‰์„ ๋…ธ๋ž€์ƒ‰์œผ๋กœ ๋ณ€๊ฒฝํ•œ๋‹ค.
	$("input").focus(function(){
    	//css: jQuery์—์„œ css๋ฅผ ์ ์šฉํ•  ๋•Œ ์“ฐ๋Š” ํ•จ์ˆ˜
         //this: ์œ„์˜ input์„ ๋”ฐ๋ผ๊ฐ„๋‹ค. ์œ„์˜ ๊ฒƒ์„ ์ด์–ด์„œ ์ ์šฉํ•œ๋‹ค.
		$(this).css("background-color","yellow");
	})
	//inputํƒœ๊ทธ์˜ ์ปค์„œ(ํฌ์ปค์Šค)๋ฅผ ์žƒ์œผ๋ฉด inputํƒœ๊ทธ์˜ ๋ฐฐ๊ฒฝ์ƒ‰์„ ํฐ์ƒ‰์œผ๋กœ ๋ณ€๊ฒฝํ•œ๋‹ค.
	$("input").blur(function(){
		$(this).css("background-color","white");
	})
})
</script>
</head>
<body>
์•„์ด๋””: <input type = "text" name = "name">
</body>

๊ฒฐ๊ณผ)

 

4.6 ์ด๋ฒคํŠธ ์ฒ˜๋ฆฌ๊ธฐ ํ•จ์ˆ˜ ์•ˆ์—์„œ ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•œ ์ •๋ณด p. 465

๋ชจ๋“  ์ด๋ฒคํŠธ ์ฒ˜๋ฆฌ ํ•จ์ˆ˜๋Š” ์ด๋ฒคํŠธ ๊ฐ์ฒด๋ฅผ ์ „๋‹ฌ๋ฐ›๋Š”๋‹ค. ์ด๋ฒคํŠธ ๊ฐ์ฒด๋Š” ๋งŽ์€ ์†์„ฑ๊ณผ ๋ฉ”์„œ๋“œ๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ๋Š”๋ฐ ๊ทธ ์ค‘์—์„œ ์œ ์šฉํ•œ ๊ฒƒ์€ ๋‹ค์Œ๊ณผ ๊ฐ™๋‹ค.

- pageX, pageY: ์ด๋ฒคํŠธ๊ฐ€ ๋ฐœ์ƒํ–ˆ์„ ๋‹น์‹œ์˜ ๋งˆ์šฐ์Šค ์œ„์น˜
- type: ์ด๋ฒคํŠธ์˜ ์ข…๋ฅ˜(ex. "click")
- which: ๋ˆŒ๋ ค์ง„ ๋งˆ์šฐ์Šค ๋ฒ„ํŠผ์ด๋‚˜ ํ‚ค

์˜ˆ์ œ) 

<style>
body{background-color:#eef;}
div{padding:20px;}
</style>
<script type="text/javascript" src="https://code.jquery.com/jquery-3.6.3.min.js"></script>
<script>
</script>
</head>
<body>
<div id="log"></div>
<script>
$(document).mousemove(function(e){
	$("#log").text("e.pageX: "+e.pageX+"e.pageY: "+e.pageY);
})
</script>
</body>

๊ฒฐ๊ณผ)


5. jQuery๋ฅผ ์ด์šฉํ•œ ์• ๋‹ˆ๋ฉ”์ด์…˜ ํšจ๊ณผ p. 466

5.1 show()์™€ hide()

$(selector).show( duration, complete );

selector: ์„ ํƒ์ž
show: ์š”์†Œ๋ฅผ ํ‘œ์‹œํ•œ๋‹ค.
duration: "slow", "fast", ๋˜๋Š” ๋ฐ€๋ฆฌ์ดˆ ๋‹จ์œ„๋กœ ์ง€์ •ํ•  ์ˆ˜ ์žˆ๋‹ค.
complete: ์ฝœ๋ฐฑํ•จ์ˆ˜๋กœ์„œ show() ๋ฉ”์„œ๋“œ๊ฐ€ ์™„๋ฃŒ๋œ ํ›„์— ํ˜ธ์ถœ๋˜๋Š” ๋ฉ”์„œ๋“œ๋ฅผ ์ง€์ •ํ•œ๋‹ค.
ex) ์•Œ๋ฆผ์ฐฝ์„ ๋„์šด๋‹ค.
In computer programming, a callback or callback function is any reference to executable code that is passed as an argument to another piece of code; that code is expected to call back (execute) the callback function as part of its job.

ํ”„๋กœ๊ทธ๋ž˜๋ฐ์—์„œ ์ฝœ๋ฐฑ(callback) ๋˜๋Š” ์ฝœ๋ฐฑ ํ•จ์ˆ˜(callback function)๋Š” ๋‹ค๋ฅธ ์ฝ”๋“œ์˜ ์ธ์ˆ˜๋กœ์„œ ๋„˜๊ฒจ์ฃผ๋Š” ์‹คํ–‰ ๊ฐ€๋Šฅํ•œ ์ฝ”๋“œ๋ฅผ ๋งํ•œ๋‹ค. ์ฝœ๋ฐฑ์„ ๋„˜๊ฒจ๋ฐ›๋Š” ์ฝ”๋“œ๋Š” ์ด ์ฝœ๋ฐฑ์„ ํ•„์š”์— ๋”ฐ๋ผ ์ฆ‰์‹œ ์‹คํ–‰ํ•  ์ˆ˜๋„ ์žˆ๊ณ , ์•„๋‹ˆ๋ฉด ๋‚˜์ค‘์— ์‹คํ–‰ํ•  ์ˆ˜๋„ ์žˆ๋‹ค.

์˜ˆ์ œ) ๋ฒ„ํŠผ์„ ๋ˆ„๋ฅด๋ฉด ์ด๋ฏธ์ง€๊ฐ€ ์„œ์„œํžˆ ํ™”๋ฉด์— ํ‘œ์‹œ๋œ๋‹ค. ํ™”๋ฉด์—์„œ ๊ฐ์ถ˜๋‹ค.

<style>
/*display:none; ์ฒ˜์Œ์—๋Š” ์ด๋ฏธ์ง€๋ฅผ ํ™”๋ฉด์—์„œ ๊ฐ์ถ˜๋‹ค. */
img{width:120px;height:100px;display:none;}
</style>
<script src="https://code.jquery.com/jquery-3.6.3.min.js">
</script>
<script>
$(document).ready(function(){
	//show ๋ฒ„ํŠผ์„ ํด๋ฆญํ•˜๋ฉด
	$("#show").click(function (){
		//$(์„ ํƒ์ž).show(duration, complete)
						//slow: ๋ฒ„ํŠผ์ด ํด๋ฆญ๋˜๋ฉด ์ด๋ฏธ์ง€๊ฐ€ ๋Š๋ฆฌ๊ฒŒ ๋‚˜ํƒ€๋‚œ๋‹ค. 
		$("#coffee").show("slow",function(){alert("์ด๋ฏธ์ง€๊ฐ€ ๋‚˜ํƒ€๋‚œ ํ›„์— ์•Œ๋ฆผ์ฐฝ์„ ๋„์šฐ์„ธ์š”.")})});
	//hide ๋ฒ„ํŠผ์„ ํด๋ฆญํ•˜๋ฉด 
	$("#hide").click(function (){
		$("#coffee").hide("slow",function(){alert("์ด๋ฏธ์ง€๊ฐ€ ์‚ฌ๋ผ์ง„ ํ›„์— ์•Œ๋ฆผ์ฐฝ์„ ๋„์šฐ์„ธ์š”.")})});
});
</script>	
</head>

<body>
<button id="show"> Show it </button>
<button id="hide"> Hide it </button>
<img id="coffee" src="image/coffee.jpg" alt="">
</body>

๊ฒฐ๊ณผ) show()๋Š” ์™ผ์ชฝ ์ƒ๋‹จ์—์„œ ์‹œ์ž‘ํ•ด์„œ ์ปค์ง€๊ณ , hide()๋Š” ์™ผ์ชฝ ์ƒ๋‹จ์ชฝ์œผ๋กœ ์‚ฌ๋ผ์ง„๋‹ค. 

 


5.2 toggle() p. 467

์š”์†Œ๊ฐ€ ๊ฐ์ถ”์–ด์ ธ ์žˆ์œผ๋ฉด ํ‘œ์‹œํ•˜๊ณ , ํ‘œ์‹œ๋˜์–ด ์žˆ์œผ๋ฉด ๊ฐ์ถ˜๋‹ค.
show(), hide()์ฒ˜๋Ÿผ ์™ผ์ชฝ ์ƒ๋‹จ์ด ๊ธฐ์ค€์ด๋‹ค. 

What is toggle CS?
A toggle, in general computing, is a switch between one setting and another. The term implies that it is a switch that has only two outcomes: A or B, or on or off. It is found in almost every aspect of computing when there is an options or preferences list.


์˜ˆ์ œ) ์ด๋ฏธ์ง€๊ฐ€ ๋‚˜ํƒ€๋‚ฌ๋‹ค ์‚ฌ๋ผ์ง€๊ธฐ๋ฅผ ๋ฐ˜๋ณตํ•œ๋‹ค.

$("#toggle").click(function (){
		$("#coffee").toggle("slow",function(){alert("ํ•˜๋‚˜์˜ ๋ฒ„ํŠผ์œผ๋กœ ๋‚˜ํƒ€๋‚˜๊ณ  ์‚ฌ๋ผ์ง„๋‹ค.")})});

<button id="toggle"> Toggle it </button>

 

๊ฒฐ๊ณผ)


5.3 animate()

animate(): ์–ด๋””๋กœ๋‚˜ ์ด๋™์ด ๊ฐ€๋Šฅํ•˜๊ณ  ์–ด๋–ค ํšจ๊ณผ๋„ ๊ฐ€๋Šฅํ•˜๋‹ค.

$(selector).animate( properties, duration, easing, complete )

selector: ์„ ํƒ์ž
animate: ์š”์†Œ๋ฅผ ์• ๋‹ˆ๋ฉ”์ดํŠธํ•˜๋‹ค.
properties: ์• ๋‹ˆ๋ฉ”์ดํŠธ๋  CSS ์†์„ฑ, ๋ชฉํ‘œ๊ฐ’์„ ์—ฌ๊ธฐ์— ์ ๋Š”๋‹ค. CSS ํ˜•์‹์œผ๋กœ ์›ํ•˜๋Š” ์†์„ฑ์„ ๋„ฃ์œผ๋ฉด ๋œ๋‹ค. 
duration: speed๋Š” "slow", "fast", ๋˜๋Š” ๋ฐ€๋ฆฌ์ดˆ ๋‹จ์œ„๋กœ ์ง€์ •ํ•  ์ˆ˜ ์žˆ๋‹ค.

Easing functions specify the rate of change of a parameter over time.

easing (default: swing) Type: String
A string indicating which easing function to use for the transition.
 
์˜ˆ์ œ) <div> ์š”์†Œ๋ฅผ ์™ผ์ชฝ์—์„œ 100px ๋–จ์–ด์ง„ ์œ„์น˜๋กœ ์ด๋™ํ•œ๋‹ค. ์ด๋ฏธ์ง€๋ฅผ ์™ผ์ชฝ์—์„œ ์˜ค๋ฅธ์ชฝ์œผ๋กœ ์˜ฎ๊ธด๋‹ค.
ํˆฌ๋ช…๋„์™€ ํฌ๊ธฐ๋„ ๋ณ€๊ฒฝ๋œ๋‹ค.

<style>
#hong{width:120px;height:100px;position:relative;}
</style>
<script type="text/javascript" src="https://code.jquery.com/jquery-3.6.3.min.js"></script>
<script>
$(document).ready(function(){
	$("button").click(function(){
		$("#hong").animate({
			left: "100px",
			opacity: "0.5",
			width:"150px"})
	})
});
</script>
</head>
<body>
<img src = "image/coffee.jpg" id="hong"><br>
<button> animate() </button>
</body>
๊ฒฐ๊ณผ)


5.4 stop()

stop(): ๋ชจ๋“  ์• ๋‹ˆ๋ฉ”์ด์…˜์„ ์ค‘๊ฐ„์— ์ค‘๋‹จํ•œ๋‹ค. 

ex) id=stop์ธ ๋ฒ„ํŠผ์ด ํด๋ฆญ๋˜์—ˆ์„ ๋•Œ, ์• ๋‹ˆ๋ฉ”์ด์…˜์„ ์ค‘์ง€ํ•œ๋‹ค.

$("#stop").click(function () {
		$("#dog").stop();
});

์˜ˆ์ œ)

<style>
#hong{width:120px;height:100px;position:relative;}
</style>
<script src="https://code.jquery.com/jquery-3.6.3.min.js"></script>
<script>
$(document).ready(function(){
	$("button").click(function(){
		$("#hong").animate({
			left: "1000px",
			opacity: "0.5",
			width:"150px"})
	});//# animate ๋
	$("#stop").click(function(){
		$("#hong").stop();
	});
});
</script>
</head>
<body>
<img src = "image/coffee.jpg" id="hong"><br>
<button> animate() </button><button id="stop"> stop() </button>
</body>

์˜ˆ์ œ 2) ์ถœ์ฒ˜: https://www.w3schools.com/jquery/tryit.asp?filename=tryjquery_stop_slide

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.1/jquery.min.js"></script>
<script> 
$(document).ready(function(){
  $("#flip").click(function(){
    $("#panel").slideDown(5000);
  });
  $("#stop").click(function(){
    $("#panel").stop();
  });
});
</script>
<style> 
#panel, #flip {
  padding: 5px;
  font-size: 18px;
  text-align: center;
  background-color: #555;
  color: white;
  border: solid 1px #666;
  border-radius: 3px;
}

#panel {
  padding: 50px;
  display: none;
}
</style>
</head>
<body>
 
<button id="stop">Stop sliding</button>

<div id="flip">Click to slide down panel</div>
<div id="panel">Hello world!</div>

</body>
</html>

๊ฒฐ๊ณผ)




5.5 fadeIn()/ fadeOut() 

The fadeIn() method gradually changes the opacity, for selected elements, from hidden to visible (fading effect).
The fadeOut() method gradually changes the opacity, for selected elements, from visible to hidden (fading effect).
Note: Hidden elements will not be displayed at all (no longer affects the layout of the page).

 

5.6 slideUp(), slideDown()

SlideUp(): ์š”์†Œ๋ฅผ ๋ฐ€์–ด์˜ฌ๋ฆฐ๋‹ค.
SlideDown(): ์š”์†Œ๋ฅผ ๋ฐ€์–ด๋‚ด๋ฆฐ๋‹ค.

<style>
/*display:none; ์ฒ˜์Œ์—๋Š” ์ด๋ฏธ์ง€๋ฅผ ํ™”๋ฉด์—์„œ ๊ฐ์ถ˜๋‹ค. */
img{width:120px;height:100px;display:none;}
</style>
<script src="https://code.jquery.com/jquery-3.6.3.min.js">
</script>
<script>
$(document).ready(function(){
	//show ๋ฒ„ํŠผ์„ ํด๋ฆญํ•˜๋ฉด
	$("#show").click(function (){
		//$(์„ ํƒ์ž).show(duration, complete)
						//slow: ๋ฒ„ํŠผ์ด ํด๋ฆญ๋˜๋ฉด ์ด๋ฏธ์ง€๊ฐ€ ๋Š๋ฆฌ๊ฒŒ ๋‚˜ํƒ€๋‚œ๋‹ค. 
		$("#coffee").show("slow",function(){alert("์ด๋ฏธ์ง€๊ฐ€ ๋‚˜ํƒ€๋‚œ ํ›„์— ์•Œ๋ฆผ์ฐฝ์„ ๋„์šฐ์„ธ์š”.")})});
	//hide ๋ฒ„ํŠผ์„ ํด๋ฆญํ•˜๋ฉด 
	$("#hide").click(function (){
		$("#coffee").hide("slow",function(){alert("์ด๋ฏธ์ง€๊ฐ€ ์‚ฌ๋ผ์ง„ ํ›„์— ์•Œ๋ฆผ์ฐฝ์„ ๋„์šฐ์„ธ์š”.")})});
	//toggle ๋ฒ„ํŠผ์„ ํด๋ฆญํ•˜๋ฉด
	$("#toggle").click(function (){
		$("#coffee").toggle("slow",function(){alert("ํ•˜๋‚˜์˜ ๋ฒ„ํŠผ์œผ๋กœ ๋‚˜ํƒ€๋‚˜๊ณ  ์‚ฌ๋ผ์ง„๋‹ค.")})});
	//fadeIn ๋ฒ„ํŠผ์„ ํด๋ฆญํ•˜๋ฉด
	$("#fadeIn").click(function (){
		$("#coffee").fadeIn("slow",function(){alert("fadeIn์€ ์˜ํ™”์ฒ˜๋Ÿผ ๋“ฑ์žฅํ•œ๋‹ค.")})});
	//fadeOut ๋ฒ„ํŠผ์„ ํด๋ฆญํ•˜๋ฉด
	$("#fadeOut").click(function (){
		$("#coffee").fadeOut("slow",function(){alert("fadeOut์€ ์˜ํ™”์ฒ˜๋Ÿผ ์‚ฌ๋ผ์ง„๋‹ค.")})});
	//slideDown ๋ฒ„ํŠผ์„ ํด๋ฆญํ•˜๋ฉด
	$("#slideDown").click(function (){
		$("#coffee").slideDown("slow",function(){alert("slideDown์€ ์š”์†Œ๋ฅผ ๋ฐ€์–ด๋‚ด๋ฆฐ๋‹ค.")})});
	//slideUp ๋ฒ„ํŠผ์„ ํด๋ฆญํ•˜๋ฉด
	$("#slideUp").click(function (){
		$("#coffee").slideUp("slow",function(){alert("slideUp์€ ์š”์†Œ๋ฅผ ๋ฐ€์–ด์˜ฌ๋ฆฐ๋‹ค.")})});	
});
</script>	
</head>

<body>
<button id="show"> Show it </button>
<button id="hide"> Hide it </button>
<button id="toggle"> Toggle it </button>
<button id="fadeIn"> Fade it in </button>
<button id="fadeOut"> Fade it out </button>
<button id="slideDown"> Slide it down </button>
<button id="slideUp"> Slide it up </button>
<img id="coffee" src="image/coffee.jpg" alt="">
</body>

๊ฒฐ๊ณผ) 

 


5.7 ๋ฉ”์„œ๋“œ ์ฒด์ด๋‹ (method chaining) p. 472

๋ฉ”์„œ๋“œ ์ฒด์ด๋‹(method chaining): ๋™์ผํ•œ ์š”์†Œ์— ๋Œ€ํ•œ ์—ฌ๋Ÿฌ ๊ฐœ์˜ ๋ฉ”์„œ๋“œ๋ฅผ ํ•˜๋‚˜๋กœ ์—ฐ๊ฒฐํ•ด์„œ ์‹คํ–‰ํ•  ์ˆ˜ ์žˆ๋‹ค. 
๋™์ผํ•œ ์š”์†Œ์— ๋Œ€ํ•œ ์—ฌ๋Ÿฌ ๊ฐœ์˜ jQuery ๋ฉ”์„œ๋“œ๋ฅผ ํ•˜๋‚˜์˜ ๋ฌธ์žฅ์œผ๋กœ ์‹คํ–‰ํ•  ์ˆ˜ ์žˆ๋‹ค. 

์˜ˆ์ œ) "#dog" ์š”์†Œ์— ๋Œ€ํ•œ show(), fadeOut(), slideDown() ๋ฉ”์„œ๋“œ๋ฅผ ์—ฐ๊ฒฐํ•ด์„œ ํ˜ธ์ถœํ•œ๋‹ค.
"#dog" ์š”์†Œ๋Š” ํ™”๋ฉด์— ๋‚˜ํƒ€๋‚˜๊ณ  ์ด์–ด์„œ ํŽ˜์ด๋“œ์•„์›ƒ, ์Šฌ๋ผ์ด๋“œ๋‹ค์šด๋œ๋‹ค.

<style>
#coffee{width:120px;height:100px;display:none;}
</style>
<script src="https://code.jquery.com/jquery-3.6.3.min.js"></script>
<script>
$(document).ready(function(){
	$("button").click(function(){
		$("#coffee").show().fadeOut("slow").slideDown("slow");
	})
});
</script>
</head>
<body>
<button>๋ฉ”์„œ๋“œ ์ฒด์ด๋‹ ์‹œ์ž‘</button><br>
<img src="image/coffee.jpg" id="coffee">
</body>

๊ฒฐ๊ณผ)


 

728x90
๋ฐ˜์‘ํ˜•
Comments