2011-12-15 3 views
0
(function($){ 
    var screen_width = 0; 
    var screen_scroll = 0; 
    var help_width = 0; 
    var help_height = 0; 

    var help_cont = ''; 
    var help_offset = 0; 
    var help_html = ''; 

    var hover_status = false; 

    $(".helpme").live("mouseenter",function(){ 
     hover_status = true; 

     screen_width = $("body").width(); 
     screen_scroll = $(window).scrollTop(); 

     help_cont = $(this).attr("help"); 
     help_offset = $(this).offset(); 

     help_html = '<div id="helper_back"></div><div id="helper"><div id="helper_cont">'; 

    help_html += ''; 
    help_html += '</div></div>'; 

     $("body").append(help_html); 
     calc_size(); 

     $(this).bind("mouseleave",function(){ 
      $("#helper_back").css("top",-9999).remove(); 
      $("#helper").remove(); 
      hover_status = false; 
     }); 
    }); 

    $(document).bind("mousemove",function(e){ 
     if(hover_status === true) { 
     calc_size(); 
      var local_left = e.pageX + 20; 

      var local_top = e.pageY - help_height - 15; 
      if(local_left + help_width > screen_width - 20) { 
       local_left = screen_width - 20 - help_width; 
      } 
      if(local_top < screen_scroll) {local_top = e.pageY + 20}; 
      $("#helper_back").css("left",local_left).css("top",local_top); 
      $("#helper").css("left",local_left + 3).css("top",local_top + 3); 
      $("#helper_cont").css("visibility","visible"); 
     } 
    }); 

    function calc_size() { 
     help_width = $("#helper").width(); 
     help_height = $("#helper").height(); 
     if(help_width > 300) {help_width = 300}; 
     $("#helper_back").width(help_width).height(help_height); 
     $("#helper").width(help_width); 
    } 

})(jQuery); 

저는이 코드를 수정하여 ajax로 help_html을 빌드 할 수있었습니다. 먼저 파일 (test.html)을 문자열로 읽는 데 몇 가지 문제점이 있습니다. 둘째로 Chorme과 Opera에서 전혀 열지 않으려 고 노력했습니다. 어떤 제안이 왜이 스크립트는 크롬과 오페라에서 작동하지 않지만 모질라에서 일하고 있습니까 ???은 mozila에서 작동하는 크롬 및 오페라에서 작동하지 않습니다.

+0

정확하게 작동하지 않는 부분을 도와 줄 수 있습니까? –

답변

1

사용 '마우스 오버'대신 'mouseenter'와 '하는 MouseLeave'의 '로 마우스'이벤트 :

+0

Chrome forx에서 해결되었지만 Opera가 여전히 작동하지 않습니까? – user1080711

+0

다시 한번 살펴 보겠습니다. –

+0

여기에 html과 스크립트를 입력 할 수 있습니까? [link] (http://jsfiddle.net/) –

0

또한, 크롬에서 예상 값을 반환하지 않습니다 scrollTop()을 보인다. Check this out (최신 응답을 얻으려면 스레드의 맨 아래로 이동).

관련 문제