2011-12-15 21 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とオペラでそれを開こうとしました。 ChromeとOperaでこのスクリプトが動作しない理由は何ですか?しかし、Mozillaで作業していますか?はmozilaで働いているクロムとオペラでは働いていません

+0

正確にはどの部分がうまく動作しないのですか? –

答えて

1

使用「マウスオーバー」、代わりに「MouseEnterイベント」と「mouseleave」の「マウスアウト」イベント:

+0

Chrome forxで解決されたOperaはまだ動作していませんか? – user1080711

+0

もう一度見てみましょう –

+0

ここにhtmlとスクリプトを入力できますか:[リンク](http://jsfiddle.net/) –

0

また、scrollTopスプライトは()Chromeで期待値を返さないようです。 Check this out(最新の返答のためにスレッドの最下部にナビゲートする)。

関連する問題