0

我正在尝试在鼠标悬停和鼠标悬停时更改 div 的背景颜色。在 MouseOver 上立即变为黄色,在 MouseOut 上缓慢淡出。

function hilightel(keydiv)
{
$('#'+keydiv).animate({ backgroundColor: '#ffffd3' },1);
}
function lolightel(keydiv)
{
$('#'+keydiv).animate({ backgroundColor: '#ffffff' },300);
}

< div onMouseOver=javascript:highlightel('item1'); onMouseOut=javascript:lolightel('item1'); id='item1'>内容</div>

但是,当鼠标移到 div 中的文本上时,它会认为我已经鼠标移出,因此闪烁得很厉害。

不起作用的替代方案:
- animateToClass 不支持背景颜色,所以我使用“颜色”插件
- 我听说 switchClass 在 Chrome 中不起作用
- 不能使用 .hover 因为它们将被动态命名页面中的 div 所以需要一个通用功能

提前致谢...

4

2 回答 2

1

为什么不简单地为 div(s) 分配一个类,然后使用 .hover 来定位它们?

编辑

试试这个:

$(".myclass").hover(
function(){
    $(this).animate({ backgroundColor: '#ffffd3' },1);
    },
    $(this).animate({ backgroundColor: '#ffffff' },300);
    }
);
于 2009-12-16T17:42:26.377 回答
0

最终解决方案:

$(document).ready(function()
{
$('.a_editableitem').bind('mouseenter', function() { $(this).animate({ backgroundColor: '#ffffd3' },25); }) ;
$('.a_editableitem').bind('mouseleave', function() { $(this).animate({ backgroundColor: '#ffffff' },250); });
});

Flickering has stopped although still gets 'stuck' on yellow sometimes.

于 2009-12-16T21:13:08.400 回答