중앙정렬만 하면 툴팁 좌표가 어긋납니다.
그누 전체를은 div wrapper로 감싼후
div.wrapper { width:800px; margin:0 auto;}으로 처리하여 가운데 정렬해서 사용중입니다.
아래는 사용하는 툴팁이구요..
<script>
$(document).ready(function() {
var tip = null;
$(".tt").hover(function(){
tip = $(this).find('.tp');
var id = $(this).attr('title');
if ($('#item' + id).length <= 0)
{
$.ajax( {
type:'GET',
url: '주소'+id ,
dataType: 'html',
success: function (html, textStatus) {
tip.append(html);
}
} );
}
tip.css({position:'absolute'}).show(); //Show tooltip
}, function() {
tip.hide().remove(); //Hide and remove tooltip appended to the body
$(this).append(tip); //Return the tooltip to its original position
}).mousemove(function(e) {
//console.log(e.pageX)
if ( tip == null ) return;
var mousex = e.pageX + 20; //Get X coodrinates
var mousey = e.pageY + 20; //Get Y coordinates
var tipWidth = tip.width(); //Find width of tooltip
var tipHeight = tip.height(); //Find height of tooltip
//Distance of element from the right edge of viewport
var tipVisX = $(window).width() - (mousex + tipWidth);
var tipVisY = $(window).height() - (mousey + tipHeight);
if ( tipVisX < 20 ) { //If tooltip exceeds the X coordinate of viewport
mousex = e.pageX - tipWidth - 20;
$(this).find('.tp').css({ top: mousey, left: mousex });
} if ( tipVisY < 20 ) { //If tooltip exceeds the Y coordinate of viewport $(this).find('.tip').css({ top: mousey, left: mousex });
mousey = e.pageY - tipHeight - 20;
tip.css({ top: mousey, left: mousex });
} else {
tip.css({ top: mousey, left: mousex });
}
});
});
</script>
그리고 본문 제목에 <a class= "tt" href = "그누 변수값으로 겟" title ="그누 변수" >제목 <span class="tp"></span></a>로 사용했습니다.
근데 이게 margin:0 뒤에 auto를 안줄땐 좌표가 제대로 잡힙니다.
하지만 중앙정렬하면 꼭 좌표가 어긋납니다.. 창크기가 늘어감에따라 어긋납니다.
코드 자체를 딱 바라진 않습니다.
어느 부분에 어느부분을 더하거나 제해야한다 이런 정도의 힌트라도 알려주시면 감사하겠습니다.
혼자 이것저것 해보다 결국 벽에 부딫혀 글을 올립니다.
|
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기
댓글 5개
px 단위를 써줘야한다는부분은 css 부분 말이신가요.
아. 그리고 해당 경우면 부모 엘리먼트가 absolute, relative, fixed 같은 경우가 적용되 있는거군요... 참고가 되었습니다.
음 그리고 조금더 힌트를 주실수 없을까요.. ㅎㅎ 스타일 포지션은 사실 거의 모르다보니.. 이해가 다 되진 않았어요.
그리고 네. absolute는 절대 좌표 기준을 부모를 가립니다. relative는 현위치에서 작동되지만 absolute는 부모를 기준으로 작동됩니다. 다른 이렇다할 것이 없으면 최상위에서 작동되어 그렇게 생각하지만 어떤 부모내에서 위치시키기 위한 기준으로 사용가능하기에, 트릭같이 relative로 놓고 사용하기도 하고요. ㅎ