Develop
2021.02.03 16:13
[js] show/hide 이벤트 감시 (Observing show/hide event)
조회 수 2607 댓글 0
Observing show/hide events with jQuery.
HTML Code
<button id="btnShow">Show</button>
<button id="btnHide">Hide</button>
<div class="container">
<div id="foo">
I am #foo
</div>
</div>
<div id="console">
</div>
CSS Code
.container {
height:60px;
margin:10px;
}
#foo {
background-color:#eeeeee;
width:150px;
height:50px;
text-align:center;
font-size:20px;
}
JQuery Code
//The magic code to add show/hide custom event triggers
(function ($) {
$.each(['show', 'hide'], function (i, ev) {
var el = $.fn[ev];
$.fn[ev] = function () {
this.trigger(ev);
return el.apply(this, arguments);
};
});
})(jQuery);
//on Show button click; show the #foo div
$('#btnShow').click(function(){
$('#foo').show();
});
//on Hide button click; hide the #foo div
$('#btnHide').click(function(){
$('#foo').hide();
});
//Add custom handler on show event and print message
$('#foo').on('show', function(){
$('#console').html( $('#console').html() + '#foo is now visible'+ '<br>' )
});
//Add custom handler on hide event and print message
$('#foo').on('hide', function(){
$('#console').html( $('#console').html() + '#foo is hidden'+ '<br>' )
});
[출처] https://www.viralpatel.net/jquery-trigger-custom-event-show-hide-element/
번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|---|
21 | Develop | [c] 소수점 반올림^^ | hooni | 2003.04.23 | 8480 |
20 | Develop | [c] 최대공약수 알고리즘 (유클릿) | hooni | 2003.04.23 | 8877 |
19 | Develop | [php] whois정보 조회 프로그램 | hooni | 2003.04.23 | 11737 |
18 | Develop | [c] 간단한 링크드 리스트(linked list) 자료형 예제.. | hooni | 2003.04.23 | 9842 |
17 | Develop | [c] CGI Library to C^^ | hooni | 2003.04.23 | 8425 |
16 | Develop | [c] scanf(), printf() 포맷의 형변환 | hooni | 2003.04.23 | 10858 |
15 | Develop | [c] home env stack overflow | hooni | 2003.04.23 | 11519 |
14 | Develop | [c] 파일입출력 간단한 설명 | hooni | 2003.04.23 | 11246 |
13 | Develop | [C] C언어의 조건 연산자(Conditional Operator) | hooni | 2003.04.23 | 14231 |
12 | Database | [mysql] 접속과 테이블 생성 간단한 설명.. | hooni | 2003.04.23 | 18660 |
11 | Develop | [vb] 비쥬얼 베이직으로.. | hooni | 2003.04.23 | 53008 |
10 | Develop | [c] 재미있는 코딩.. | hooni | 2003.04.23 | 21323 |