我有几个由 PHP 生成的 div,它们的设置如下
<div style="width:215px;height:305px;background-color: rgba(255, 255, 255, 0.5);background-position: 0px 0px;background-repeat: no-repeat;background-size: 215px 305px;display:none;position:fixed;top:100px;left:100px;" id="more####"></div>
将 id 中的 # 替换为一个数字(并不总是 4 个数字),并将它们的背景图像设置在另一个自动生成的 css 文件中。擦除display:none;
它们可以让它们全部显示为 100、100,背景非常好。
但是我希望使用 JQuery 创建一个 javascript 文件,以便当我将鼠标悬停在表行设置上时
<tr id="yellow" class="yellow ####">
“黄色”是“黄色”、“绿色”、“红色”、“alt”,或者在 id 和 class 中都没有。匹配数字的 div 将出现在鼠标位置。如果可能的话,它会随着鼠标移动,直到鼠标不再悬停在表格行上,然后它会再次隐藏。
我从上一个 stackoverflow 问题中得到了下面的代码,并对其进行了编辑以应用于我的表格的第一行,但它不起作用。第一行如下:
<tr id="red" class="red 9776">
和 div 是
<div id="more9776" style="width:215px;height:305px;background-color: rgba(255, 255, 255, 0.5);background-position: 0px 0px;background-repeat: no-repeat;background-size: 215px 305px;display:none;position:fixed;top:100px;left:100px;"></div>
任何想法为什么下面的代码不起作用?
var mouseX;
var mouseY;
$(document).mousemove( function(e) {
mouseX = e.pageX;
mouseY = e.pageY;
});
$(".9776").mouseover(function(){
$('#more9776').css({'top':mouseY,'left':mouseX}).fadeIn('slow');
});
$(".9776").mouseout(function(){
$('#more9776').fadeOut('slow');
});
同样,如何在不为每一行定义 mouseover 和 mouseout 的情况下将代码应用于所有表行?