posts - 72, comments - 66, trackbacks - 0, articles - 0

css hover 与 jquery

Posted on 2009-05-21 10:51 Fingki.li 阅读(3755) 评论(0)  编辑  收藏 所属分类: About development
hover是鼠标悬停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");
            });
});



只有注册用户登录后才能发表评论。


网站导航: