※ fadeIn(), fadeOut(), fadeTo(), fadeToggle() 예제
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
// fadeIn
$("#btn1").click(function(){
$("#div1").fadeIn();
$("#div2").fadeIn("slow");
$("#div3").fadeIn(3000);
});
// fadeOut
$("#btn2").click(function(){
$("#div1").fadeOut();
$("#div2").fadeOut("slow");
$("#div3").fadeOut(3000);
});
// fadeToggle
$("#btn3").click(function(){
$("#div1").fadeToggle();
$("#div2").fadeToggle("slow");
$("#div3").fadeToggle(3000);
});
// fadeTo
$("#btn4").click(function(){
// fadeTo(speed,opacity,callbakc)
// fadeTo("slow",0.15);
$("#div1").fadeTo("slow",0.15);
$("#div2").fadeTo("slow",0.4);
$("#div3").fadeTo("slow",0.7);
});
});
</script>
</head>
<body>
<p>Demonstrate fadeIn() with different parameters.</p>
<button id="btn1">Click to fade in boxes</button><br><br>
<button id="btn2">Click to fade out boxes</button><br><br>
<button id="btn3">Click to fade toggle boxes</button><br><br>
<button id="btn4">Click to fade fadeto boxes</button><br><br>
<div id="div1" style="width:80px;height:80px;display:none;background-color:red;"></div><br>
<div id="div2" style="width:80px;height:80px;display:none;background-color:green;"></div><br>
<div id="div3" style="width:80px;height:80px;display:none;background-color:blue;"></div>
</body>
</html>
※ fadeIn(), fadeOut() 버튼 눌렀을 때
※ fadeTo(), fadeToggle() 버튼 눌렀을 때
'jQuery 수업' 카테고리의 다른 글
jQuery-8(animate()) (0) | 2020.02.19 |
---|---|
jQuery-7(이벤트 slideUp(), slideDown()) (0) | 2020.02.19 |
jQuery-5(이벤트 toggle) (0) | 2020.02.19 |
jQuery-4(이벤트 hide(), show()) (0) | 2020.02.19 |
jQuery-3(마우스 이벤트, mouseenter, mouseleave, mousedown, mouseup) (0) | 2020.02.19 |