Develop
2021.02.03 16:13
[js] show/hide 이벤트 감시 (Observing show/hide event)
조회 수 2742 댓글 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 | [js] 사진첩에 쓸 내용 - 마우스 오버로 바꾸기 | hooni | 2013.04.23 | 6355 |
216 | Develop | [c][php] 프로세스정보와 메모리 정보 웹으로 출력하는거.. | hooni | 2013.04.23 | 6337 |
215 | Develop | [java] 에디터.. swing 사용 | hooni | 2013.04.23 | 6324 |
214 | Develop | [js] 서서히 나타나는 화면.. ㅋㅋ | hooni | 2013.04.23 | 6217 |
213 | Develop | [doc] C++언어 문법 설명서 | hooni | 2013.04.23 | 6187 |
212 | Develop | [js] 자바스크립트 escape()를 PHP로 받기 | hooni | 2013.04.23 | 6001 |
211 | Develop | [c] 윈도우 API Viewport와 Window | hooni | 2013.04.23 | 5974 |
210 | Develop | [ios] Using protobuf(Protocol Buffers) on iPhone (iOS) | hooni | 2014.03.20 | 5007 |
209 | Develop | [PHP] Mac OS에서 PHP 7 설치하기 | hooni | 2018.05.11 | 4987 |
208 | Develop | [android] 안드로이드 동영상 스트리밍 예제 2 | hooni | 2015.01.02 | 4909 |
207 | Develop | [ios] UITableView 특정 Row만 Update | hooni | 2014.04.08 | 4834 |
206 | Develop | [ios] UUID 생성 + Key Chain 연동 | hooni | 2016.05.13 | 4761 |