Develop
2021.02.03 16:13
[js] show/hide 이벤트 감시 (Observing show/hide event)
Views 2825 Comment 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/
No. | Category | Subject | Author | Date | Views |
---|---|---|---|---|---|
637 | Develop | [ios] Objective-C 프로퍼티의 strong, weak, assign | hooni | 2014.03.17 | 4751 |
636 | Develop | [ios] UUID 생성 + Key Chain 연동 | hooni | 2016.05.13 | 4793 |
635 | Develop | [ios] UITableView 특정 Row만 Update | hooni | 2014.04.08 | 4849 |
634 | Develop | [android] 안드로이드 동영상 스트리밍 예제 2 | hooni | 2015.01.02 | 4928 |
633 | Develop | [ios] Using protobuf(Protocol Buffers) on iPhone (iOS) | hooni | 2014.03.20 | 5022 |
632 | Develop | [PHP] MacOS에서 PHP 7 설치하기 | hooni | 2018.05.11 | 5056 |
631 | Develop | [c] 윈도우 API Viewport와 Window | hooni | 2013.04.23 | 5984 |
630 | Develop | [js] 자바스크립트 escape()를 PHP로 받기 | hooni | 2013.04.23 | 6003 |
629 | Develop | [doc] C++언어 문법 설명서 | hooni | 2013.04.23 | 6195 |
628 | Develop | [js] 서서히 나타나는 화면.. ㅋㅋ | hooni | 2013.04.23 | 6233 |
627 | Develop | [java] 에디터.. swing 사용 | hooni | 2013.04.23 | 6336 |
626 | Develop | [c][php] 프로세스정보와 메모리 정보 웹으로 출력하는거.. | hooni | 2013.04.23 | 6347 |