마우스를 이미지가 바뀌고 그에 따라 위치가 조정되면 요소를 만들려고합니다. 그러나 이미지가 바뀌고 있지만 CSS 위치는 바뀌지 않습니다.중첩 된 jQuery 함수 내에서 CSS를 어떻게 바꿀 수 있습니까?
jQuery를/자바 스크립트 :
var newComment = $('<span>').attr({'id': commentCount});
newComment
.addClass('comment')
.css({
'top': (yOffset * 100) + 175 + "px",
'left': (xOffset * 75) + 40 + "px"
})
.hover(function(){ //Hover over the comment
newComment
.removeClass()
.addClass('commentOver')
.offset({
'top': yOffsets[newComment.id] + 175 - 1250 + "px",
'left': xOffsets[newComment.id] + 40 - 1500 + "px"
});
},function(){ //Mouse leaves the comment
newComment
.removeClass()
.addClass('comment')
.offset({
'top': yOffsets[newComment.id] + 1750 + "px",
'left': xOffsets[newComment.id] + 400 + "px"
});
});
CSS :
.comment{
position: absolute;
z-index: 10;
padding: 0px;
width: 51px;
height: 70px;
background-image: url('../img/dropSmall.png');
font-weight:800;
}
당신이 볼 수 내가 잘못 가고 왜 해요?
매개 변수없이 'removeClass()'메소드를 호출하면 클래스 속성이 비 웁니다. '$ (selector) .removeClass(). attr ('class');'시도해 보라. 빈 문자열을 반환해야합니다. –
그럴 수도 있지만 설명서에 허용되는 것은 아닙니다. 실제로 매개 변수는 하나 이상의 클래스 이름이어야합니다. 나는 문서가 명시 적으로 지원하지 않는 것들로부터 멀리 떨어져있다. 'toggleClass()'는 어쨌든 여기에 맞는 해결책 일 수도 있고'this.className = "";'을 설정하는 것일 수도 있습니다. – jfriend00
문서화되지 않았지만 패턴과 같습니다. 'unbind (/ * 모든 이벤트 * /)','die ('/ * 모든 이벤트 * /')','get (/ * no index => 모든 요소들) * /)' –