zoukankan      html  css  js  c++  java
  • IE6鼠标悬停Bug

    当鼠标放置于某个文字链接之上,文字或文字背景改变为其他颜色或样式的效果是我们最经常见到的鼠标悬停效果。在CSS中,这个效果靠伪元素:hover来实现,只不过在文字链接中:hover被应用在了锚点元素<a>上。实际上,在CSS2中,:hover伪元素可以应用于任何html元素上。比如,

    1 P :hover{background-color:#F7F7F7;}

    这一CSS语句就可以改变鼠标悬停在一个段落文字之上的文字背景色。而在网页设计中,:hover伪元素一个常见用法的例子是突出列表中被选中的行,通常是改变它们的背景色,这样可以防止看走行。

    但是,遗憾的是,IE6及其以下版本不支持除锚点元素<a>之外的其他html元素的鼠标悬停效果。当然,这个问题也不是没有解决方法。我们可以使用Whatever:hover 3.11来帮助IE6实现这样的效果。

    首先,下载Whatever:hover 3.11文件。然后在你的CSS中,给body元素应用

    1 body {behavior: url("csshover3.htc");}

    代码,更改其中的url地址来引用此文件,之后IE6就能够支持其他元素的鼠标悬停效果了。具体这种方法是如何实现IE6的鼠标悬停效果的,可以查看这篇文章。


    P :hover{background-color:#F7F7F7;}

    csshover3.htc 

    <public:attach event="ondocumentready" onevent="CSSHover()" />
    <script>
    /**
     * Whatever:hover - V3.11
     * http://www.xs4all.nl/~peterned/
     *    
     * Copyright (c) 2009 Peter Nederlof
     * Licensed under the LGPL license
     * http://creativecommons.org/licenses/LGPL/2.1
     */
    window.CSSHover=(function(){var m=/(^|s)((([^a]([^ ]+)?)|(a([^#.][^ ]+)+)):(hover|active|focus))/i;var n=/(.*?):(hover|active|focus)/i;var o=/[^:]+:([a-z-]+).*/i;var p=/(.([a-z0-9_-]+):[a-z]+)|(:[a-z]+)/gi;var q=/.([a-z0-9_-]*on(hover|active|focus))/i;var s=/msie (5|6|7)/i;var t=/backcompat/i;var u={index:0,list:['text-kashida','text-kashida-space','text-justify'],get:function(){return this.list[(this.index++)%this.list.length]}};var v=function(c){return c.replace(/-(.)/mg,function(a,b){return b.toUpperCase()})};var w={elements:[],callbacks:{},init:function(){if(!s.test(navigator.userAgent)&&!t.test(window.document.compatMode)){return}var a=window.document.styleSheets,l=a.length;for(var i=0;i<l;i++){this.parseStylesheet(a[i])}},parseStylesheet:function(a){if(a.imports){try{var b=a.imports;var l=b.length;for(var i=0;i<l;i++){this.parseStylesheet(a.imports[i])}}catch(securityException){}}try{var c=a.rules;var r=c.length;for(var j=0;j<r;j++){this.parseCSSRule(c[j],a)}}catch(someException){}},parseCSSRule:function(a,b){var c=a.selectorText;if(m.test(c)){var d=a.style.cssText;var e=n.exec(c)[1];var f=c.replace(o,'on$1');var g=c.replace(p,'.$2'+f);var h=q.exec(g)[1];var i=e+h;if(!this.callbacks[i]){var j=u.get();var k=v(j);b.addRule(e,j+':expression(CSSHover(this, "'+f+'", "'+h+'", "'+k+'"))');this.callbacks[i]=true}b.addRule(g,d)}},patch:function(a,b,c,d){try{var f=a.parentNode.currentStyle[d];a.style[d]=f}catch(e){a.runtimeStyle[d]=''}if(!a.csshover){a.csshover=[]}if(!a.csshover[c]){a.csshover[c]=true;var g=new CSSHoverElement(a,b,c);this.elements.push(g)}return b},unload:function(){try{var l=this.elements.length;for(var i=0;i<l;i++){this.elements[i].unload()}this.elements=[];this.callbacks={}}catch(e){}}};var x={onhover:{activator:'onmouseenter',deactivator:'onmouseleave'},onactive:{activator:'onmousedown',deactivator:'onmouseup'},onfocus:{activator:'onfocus',deactivator:'onblur'}};function CSSHoverElement(a,b,c){this.node=a;this.type=b;var d=new RegExp('(^|\s)'+c+'(\s|$)','g');this.activator=function(){a.className+=' '+c};this.deactivator=function(){a.className=a.className.replace(d,' ')};a.attachEvent(x[b].activator,this.activator);a.attachEvent(x[b].deactivator,this.deactivator)}CSSHoverElement.prototype={unload:function(){this.node.detachEvent(x[this.type].activator,this.activator);this.node.detachEvent(x[this.type].deactivator,this.deactivator);this.activator=null;this.deactivator=null;this.node=null;this.type=null}};window.attachEvent('onbeforeunload',function(){w.unload()});return function(a,b,c,d){if(a){return w.patch(a,b,c,d)}else{w.init()}}})();
    </script>

    body {behavior: url("csshover3.htc");}

  • 相关阅读:
    第二次作业
    大学——新生活方式
    第四次作业
    第三次作业
    第二次作业——起航
    梦开始的地方
    第四次作业
    第三次作业
    第二次作业
    博客作业 随笔
  • 原文地址:https://www.cnblogs.com/aimyfly/p/3193278.html
Copyright © 2011-2022 走看看