본문 바로가기

탭메뉴 클릭하면 텝메뉴가 달라짐은 .on클래스가 추가되고 style에 .on을 정의해놔서임... #wrap {width:939px; margin-left:400px;}#wrap ul {margin-top:140px;}#wrap ul:after {content:""; display:block; clear:both;}#wrap ul li {float:left; overflow:hidden; height:25px; margin-right:6px; }#wrap ul li:last-child { margin-right:0px; }#wrap ul li img {margin-top:0x}#wrap ul li .on img {margin-top:-10px} #content {position:relative; width:487.. 더보기
jQuery stopPropagation() stopPropagation() html * { margin:0; padding:0; }body { margin-left:300px; margin-top:60px; }#parent { width:200px; height:200px; border:1px solid red; background-color: yellow; padding:150px;}#child { width:200px; height:200px; background-color: red; color:#FF0000 }$(document).ready(function(){$('#child').bind('click', function(event){event.stopPropagation(); // 주석처리후에 실행하면 자식엘리먼트 클릭시 부모엘리먼트도 클.. 더보기
jQuery 이벤트 모델 전파 과정 최상위 루투에서 자식 엘리먼트들을 타고 이벤트의 타깃까지 내려가는 캡쳐 단계가 일어나고 다시 반대로 이벤트의 타깃으로부터 최상위 루트까지 올라가는 버블 단계가 일어납니다. 부모엘리먼트와 자식 엘리먼트 두곳에 click이벤트를 생성 하고 자식 엘리먼트를 클릭할 경우클릭하지 않은 부모엘리먼트에서 클릭이 발생하게 됩니다. 이런 의도치 않은 반응이 일어나는 문제는 이벤트 모델의 전파과정 중 버블링 단계에서 이벤트를 발생하기 때문입니다. ※ 하지만 event 객체에 stopProgation() 메서드를 호출하면 이단계가 진행되지 않도록 사전에 차단 할 수 이습니다. 더보기
jQuery event 프로퍼티 이벤트가 발생되면 이벤트에 매개변수로 넘긴 콜백함수가 호출 되는데이때 매개변수로 event객체를 넘겨줍니다. 이 이벤트 객체의 프로퍼티는 이벤트 발생시 얻을 수 잇는 정보가 있으며, 이벤트 모델의 전파과정을 컨트롤 할 수 있는 메서드를 포함합니다. 브라우저 기본동작이 발생하지 않도록 하는 메서드도 포함합니다. $(document).ready(function(){ $('#box').click(function(event){var clientyx = (event.clientX); // coument에서 스크롤 이동값을 제외하고 마우스 x좌표var clienty = (event.clientY); // coument에서 스크롤 이동값을 제외하고 마우스 y좌표var offsetx = (event.offsetX); .. 더보기
jQuery trigger() 메서드 사용 trigger()마우스를 엘리먼트에 마우스오버하지 않고 어떤 버튼을 클릭했을때 마우스오버 이벤트를 발생하고 싶을 때! $(document).ready(function(){var box = $('#box');box.bind({mouseover:function(){var tg = $(this);tg.removeClass().addClass('over');tg.find('> p').text('mouseover');},mouseout:function(){var tg = $(this);tg.removeClass().addClass('out');tg.find('> p').text('mouseout');},click:function(){var tg = $(this);tg.removeClass().addClass('c.. 더보기
jQuery 이벤트타입명으로 메서드 호출 bind() : 하나의 엘리먼트에 여러가지 이벤트를 생성 하는 경우 유리 box.bind({},mouseout:function(){var target = $(this); target.removeClass().addClass('mouseout');target.find('> p').text('mouseout 이벤트 발생');},mousedown:function(){var target = $(this);target.removeClass().addClass('mousedown');target.find('> p').text('mousedown 이벤트 발생');},mouseup:function(){var target = $(this); target.removeClass().addClass('mouseup');tar.. 더보기
jQuery on() 동적으로 추가된 엘리먼트 이벤트 발생시키기 on() 메서드 [box 추가 ] 버튼을 클릭하면 동적으로 box엘리먼트가 추가 됩니다.기존의 box 엘리먼트의 이벤트는 잘 동작하지만 동적으로 추가된 box엘리먼트에는 이벤트가 동작하지 않습니다. 이것은 bind() 메서드는 동적으로 생성된 엘리먼트를 찾지 못하기 때문입니다.on() 메서드로 수정하여 동적으로 추가된 엘리먼트의 이벤트가 동작하도록 수정합니다. html * { margin:0; padding:0; } #wrapper { margin-left:300px; } #nav > input { margin-left:300px; } .box { width:150px; height:150px; border:2px solid blue;} .box.over { background-color: red; } .. 더보기
jQuery 이벤트 bind() bind( eventType, data, handler) html * { margin:0; padding:0; }#box { width:200px; height:200px; border:2px solid blue; margin-left:300px; margin-top:200px; background-color:blue;}#box.mouseover { background-color: red; }#box.mouseout { background-color: green; }#box.mousedown { background-color: purple; }#box.mouseup { background-color: #FF9C00; }#box > p { padding:30px; color:white; } $(docume.. 더보기
jQuery 엘리먼트 감싸기 풀어내기 wrap(wrappingElement) : 각요소를 매개변수로 감사줍니다.wrapAll(wrappingElement) : 모든 요소를 매개변수로 감싸줍니다.wraplnner(wrappingElement) : 각 요소를 매개변수로 감싸줍니다.unwrap(wrappingElement) : 요소를 감싸고 있는 부모엘리멘트를 제거합니다. ① wrap() wrap() 메서드의 경우 select한 엘리먼트의 확장 집합을 개별적으로 wrapping을 한다. wrapAll() 메서드의 경우 select한 엘리먼트의 확장 집합의 전체를 모아 한번에 wrapping을 한다. wrap() 메서드의 경우 select한 엘리먼트의 확장 .. 더보기
jQuery 엘리먼트 메서드 append(html 문자열) : html문자열 추가 또는 이동prepend(html 문자열) : 맨 앞에 html 문자열을 추가 또는 이동 before(html 문자열) : 바로 앞에 html 문자열 추가 또는 이동 after(html 문자열) : 형제엘리먼트의 바로 뒤에 html 문자열을 추가 또는 이동appendTo(target) : 자식엘리먼트 중 맨 뒤로 이동prependTo(target) : 자식엘리먼트 중 맨 앞으로 이동시킵니다.insertBefore(targets) : 형제엘리먼트 바로 앞으로 이동시킵니다. insertAfter(targets) : 형제엘리먼트 바로 뒤로 이동시킵니다, ① append() 메서드 활용_html문자열 추가 또는 이동.newElement { color:red; .. 더보기