Welcome

首页 / 脚本样式 / jQuery / css hover与jquery

css hover与jquery2011-01-30 blogjava Fingki.lihover是鼠标悬停css效果,但在一些浏览器如ie6中,只对<a href=""/>有效。

jQuery可以为我们解决这个问题:

jQuery提供的hover()

方法做为一个事件,不仅可以改变CSS样式的,还可以做其他动作;

非常类似于mouseover mouseout的组合。

代码如下:

$(function(){
$(".htest").hover(
function(){
$(this).css("cursor","pointer");
$(this).css("color","red");
$(this).css("position","relative");
$(this).css("top","2px");
$(this).css("left","2px");
},
function(){
$(this).css("cursor","pointer");
$(this).css("color","blue");
$(this).css("position","relative");
$(this).css("top","0px");
$(this).css("left","0px");
}
);
$(".mtest").mouseover(function(){
$(this).css("cursor","pointer");
$(this).css("color","red");
$(this).css("position","relative");
$(this).css("top","2px");
$(this).css("left","2px");
});
$(".mtest").mouseout(function(){
$(this).css("cursor","pointer");
$(this).css("color","blue");
$(this).css("position","relative");
$(this).css("top","0px");
$(this).css("left","0px");
});
});