Develop
2021.02.03 16:13
[js] show/hide 이벤트 감시 (Observing show/hide event)
조회 수 5565 댓글 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/
번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|---|
219 | Develop |
[ios] 동영상 플레이어 샘플 (for PIP Player)
![]() |
hooni | 2017.03.15 | 12913 |
218 | Develop |
[php] 한샘 전자발주 시스템..
![]() |
hooni | 2013.04.23 | 12983 |
217 | Develop | [java] 날짜 계산 (Date, SimpleDateFormat) | hooni | 2013.04.23 | 13017 |
216 | Develop | SVN 명령어 (SVN command) | hooni | 2014.02.28 | 13032 |
215 | Develop |
[c++] 현승이가 준 P2P 프로그램 소스 ㅋㅋ
![]() |
hooni | 2013.04.23 | 13043 |
214 | Develop |
JSON, BSON 변환
![]() |
hooni | 2013.04.23 | 13134 |
213 | Develop |
[ios] Background 에서 네트워크 사용
![]() |
hooni | 2013.07.22 | 13153 |
212 | Develop |
Mac OS 에 Jenkins 설치하기 (Homebrew)
2 ![]() |
hooni | 2017.03.15 | 13254 |
211 | Develop | [c++] 기초강좌 #03(함수의 매개변수 전달) | hooni | 2003.04.23 | 13341 |
210 | Develop |
[c] 네트워크 트래릭 모니터링.. 졸업작품..
2 ![]() |
hooni | 2013.04.23 | 13348 |
209 | Develop |
[c] 파일입출력, 링크리스트(linked list)를 이용한 주소록(도스용) 소스코드
1 ![]() |
hooni | 2003.04.23 | 13403 |
208 | Develop |
[ios] 네트워크 인디케이터(NetworkActivityIndicator) 작동
![]() |
hooni | 2014.01.24 | 13478 |