Develop
2021.02.03 16:13
[js] show/hide 이벤트 감시 (Observing show/hide event)
조회 수 2597 댓글 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/
번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|---|
993 | System/OS | 무료로 HTTPS 적용하기 (Let's Encrypt) | hooni | 2017.10.28 | 1409 |
992 | Develop | What is difference between Get, Post, Put and Delete? | hooni | 2018.02.28 | 1412 |
991 | Etc | 아이폰의 터치스크린 정확도 | hooni | 2015.04.01 | 1425 |
990 | Etc | IT감사 기법 시험 | hooni | 2017.06.14 | 1426 |
989 | System/OS | [linux] wget 명령 사용 예제 | hooni | 2020.05.26 | 1451 |
988 | System/OS | [mac] Mac OS에서 재생되는 사운드를 녹음하는 방법 | hooni | 2016.10.03 | 1452 |
987 | System/OS | OpenSSL로 ROOT CA 생성 및 SSL 인증서 발급하기 | hooni | 2017.10.28 | 1468 |
986 | Database | [mysql] MacOS에 MySQL 설치, 설정, 암호 재설정 | hooni | 2017.12.15 | 1474 |
985 | Develop | [android] 레이아웃 사이즈 변경 (동적; programmatically) | hooni | 2016.11.07 | 1490 |
984 | Develop | [ios] binary를 C코드로 변환 | hooni | 2015.01.03 | 1536 |
983 | System/OS | [mac] OS X 요세미티 사용자가 많이 겪는 버그와 몇몇 불편사항 | hooni | 2015.01.04 | 1536 |
982 | System/OS | [svn] 하나의 SVN에서 멀티 저장소 (One svnserve, multiple repositories) | hooni | 2015.01.02 | 1551 |