(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中工作???
答案 0 :(得分:1)
使用'mouseover'和'mouseout'事件代替'mouseenter'和'mouseleave':
答案 1 :(得分:0)
此外,似乎scrollTop()没有返回Chrome中的预期值。 Check this out(导航到帖子底部以获取最新回复)。