Develop
2021.02.03 16:13
[js] show/hide 이벤트 감시 (Observing show/hide event)
조회 수 2739 댓글 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/
번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|---|
217 | Develop | [c] home env stack overflow | hooni | 2003.04.23 | 11540 |
216 | Develop | [c] 시간 관련 함수 설명과 예제.. | hooni | 2003.04.23 | 11544 |
215 | Develop | [ios] Background 에서 네트워크 사용 | hooni | 2013.07.22 | 11579 |
214 | Develop | [c] 도스 공격(DoS Attack) 프로그램 | hooni | 2013.04.23 | 11596 |
213 | Develop | [java] 초간단 싱글톤(Singleton) 패턴 샘플 코드 | hooni | 2013.11.18 | 11623 |
212 | Develop | [php] 쉘에서 실행할 때 인수(파라미터) 받기.. | hooni | 2003.04.23 | 11638 |
211 | Develop | [c++] String Tokenizer (나중에 c 코드로 변경해서 사용할 것) | hooni | 2013.04.23 | 11714 |
210 | Develop | [vbs] CD롬 뱉는 스크립트.. | hooni | 2003.04.23 | 11732 |
209 | Develop | [ios] UIWebView 쿠키 유지 | hooni | 2014.01.16 | 11744 |
208 | Develop | [php] whois정보 조회 프로그램 | hooni | 2003.04.23 | 11769 |
207 | Develop | [php] 배열 관련 함수 설명 ㅎㅎ | hooni | 2003.04.23 | 11776 |
206 | Develop | [ios] iOS In App Purchase 코드 부분 샘플 1 | hooni | 2013.11.20 | 11788 |