jQuery
[jQuery] $.cssHooks
힘없는염소
2014. 12. 19. 16:09
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | <!DOCTYPE html> <html lang="ko"> <head> <meta charset="utf-8"> <style> #target { width:50px; height:50px; border: 1px solid #000; } </style> <script src="js/jquery.js"></script> </head> <body> <button>클릭</button> <div id="target"></div> <script> // $.cssHooks은 특정 CSS값을 설정하기 위해 함수로 정의하는 방법을 제공한다. // jquery css설정시 foo값일때 후킹된다. $.cssHooks.foo = { get: function(elm, computed){ console.log(elm); console.log(computed); return $(elm).css('background-color'); }, set: function(elm, value){ console.log(elm); console.log(value); // 후킹된값 yellow return $(elm).css('background-color', 'red'); // red로 셋팅 } }; $('button').click(function(){ //임의의foo css 일때 $('#target').css('foo'); // get $('#target').css('foo', 'yellow'); // set // yellow로 셋팅하였지만 후킹되어 배경색이 red로 바뀜 }); </script> </body> </html> |
반응형