Develop
2021.02.03 16:13
[js] show/hide 이벤트 감시 (Observing show/hide event)
조회 수 2596 댓글 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/
번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|---|
705 | PPT | [doc] 발표 자료 ㅎㅎtalk4neo | hooni | 2013.04.23 | 20992 |
704 | Develop | [android] 자동차 리모컨 소스코드 | hooni | 2013.04.23 | 17082 |
703 | Develop | [js] 간단한 게임 프로토타입 (HTML5 와는 무관) | hooni | 2013.04.23 | 15154 |
702 | Develop | [js] 수학 공식을 제공하는 Math 객체 | hooni | 2013.04.23 | 15414 |
701 | Develop | [ios] 참고할만한 좋은 예제 소스.. | hooni | 2013.04.23 | 27373 |
700 | System/OS | [doc] 코코아 프로그래밍 for MACOS 관련 내 분량.. | hooni | 2013.04.23 | 20841 |
699 | Develop | [ios] 코코아 프레임워크(Cocoa Framework) 기본적인 내용~ | hooni | 2013.04.23 | 27684 |
698 | PPT | [ajax] 크로스 도메인(Cross Domain) 이슈 해결 방안 | hooni | 2013.04.23 | 21940 |
697 | Develop | [java] Interface 와 abstract | hooni | 2013.04.23 | 8707 |
696 | Develop | [spring] 스프링 IoC/DI | hooni | 2013.04.23 | 11349 |
695 | PPT | [android][ios] 알림(Notification) 기능에 대한 원리와 구현 방안 (APNS포함) | hooni | 2013.04.23 | 37853 |
694 | PPT | [android] XML파서(XMLParser)의 종류와 성능 비교에 대한 발표 자료 | hooni | 2013.04.23 | 75643 |