DIV+CSS

新疆25选7开奖结果查询:IE6中:hover不在A條件下的實現兼容方法

時間:2012-11-30 21:25:39 來源:北京樂品網站制作公司 關注:次

新疆25选7怎么算中奖钱 www.bbpno.com 寫CSS的時候經?;嵊齙絀E6下 DIV:hover不執行效果,大大損失了CSS的特性,下面講解下載IE6下實現hover的效果:

其實還可以用Javascript腳本來實現,不過如果想用CSS來定義的話就這種方法為佳。

第一步:新建立一個TXT文件,復制下面的代碼,另存為 IE6..htc

第二部:在頁面或者CSS加入

    

<style type="text/css">

body { behavior: url(ie6.htc); }   /*注意路徑*/

</style>


第二部:復制代碼

 <attach event="ondocumentready" handler="parseStylesheets" />
<script>
/**
* Whatever:hover - V2.02.060206 - hover, active & focus
* ------------------------------------------------------------
* (c) 2005 - Peter Nederlof
* Peterned - //www.xs4all.nl/~peterned/
* License - //creativecommons.org/licenses/LGPL/2.1/
*
* Whatever:hover is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* Whatever:hover is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* Credits and thanks to:
* Arnoud Berendsen, Martin Reurings, Robert Hanson
*
* howto: body { behavior:url("csshover.htc"); }
* ------------------------------------------------------------
*/

var csshoverReg = /(^|\s)((([^a]([^ ]+)?)|(a([^#.][^ ]+)+)):(hover|active))|((a|input|textarea)([#.][^ ]+)?:unknown)/i,
currentSheet, doc = window.document, hoverEvents = [], activators = {
onhover:{on:'onmouseover', off:'onmouseout'},
onactive:{on:'onmousedown', off:'onmouseup'},
onunknown:{on:'onfocus', off:'onblur'}
}

function parseStylesheets() {
if(!/MSIE (5|6)/.test(navigator.userAgent)) return;
window.attachEvent('onunload', unhookHoverEvents);
var sheets = doc.styleSheets, l = sheets.length;
for(var i=0; i<l; i++)
   parseStylesheet(sheets[i]);
}
function parseStylesheet(sheet) {
   if(sheet.imports) {
    try {
     var imports = sheet.imports, l = imports.length;
     for(var i=0; i<l; i++) parseStylesheet(sheet.imports[i]);
    } catch(securityException){}
   }

   try {
    var rules = (currentSheet = sheet).rules, l = rules.length;
    for(var j=0; j<l; j++) parseCSSRule(rules[j]);
   } catch(securityException){}
}

function parseCSSRule(rule) {
   var select = rule.selectorText, style = rule.style.cssText;
   if(!csshoverReg.test(select) || !style) return;
  
   var pseudo = select.replace(/[^:]+:([a-z-]+).*/i, 'on$1');
   var newSelect = select.replace(/(\.([a-z0-9_-]+):[a-z]+)|(:[a-z]+)/gi, '.$2' + pseudo);
   var className = (/\.([a-z0-9_-]*on(hover|active|unknown))/i).exec(newSelect)[1];
   var affected = select.replace(/:(hover|active|unknown).*$/, '');
   var elements = getElementsBySelect(affected);
   if(elements.length == 0) return;

   currentSheet.addRule(newSelect, style);
   for(var i=0; i<elements.length; i++)
    new HoverElement(elements[i], className, activators[pseudo]);
}

function HoverElement(node, className, events) {
if(!node.hovers) node.hovers = {};
if(node.hovers[className]) return;
node.hovers[className] = true;
hookHoverEvent(node, events.on, function() { node.className += ' ' + className; });
hookHoverEvent(node, events.off, function() { node.className = node.className.replace(new RegExp('\\s+'+className, 'g'),''); });
}
function hookHoverEvent(node, type, handler) {
   node.attachEvent(type, handler);
   hoverEvents[hoverEvents.length] = {
    node:node, type:type, handler:handler
   };
}

function unhookHoverEvents() {
   for(var e,i=0; i<hoverEvents.length; i++) {
    e = hoverEvents[i];
    e.node.detachEvent(e.type, e.handler);
   }
}

function getElementsBySelect(rule) {
var parts, nodes = [doc];
parts = rule.split(' ');
for(var i=0; i<parts.length; i++) {
   nodes = getSelectedNodes(parts[i], nodes);
} return nodes;
}
function getSelectedNodes(select, elements) {
   var result, node, nodes = [];
   var identify = (/\#([a-z0-9_-]+)/i).exec(select);
   if(identify) {
    var element = doc.getElementById(identify[1]);
    return element? [element]:nodes;
   }
  
   var classname = (/\.([a-z0-9_-]+)/i).exec(select);
   var tagName = select.replace(/(\.|\#|\:)[a-z0-9_-]+/i, '');
   var classReg = classname? new RegExp('\\b' + classname[1] + '\\b'):false;
   for(var i=0; i<elements.length; i++) {
    result = tagName? elements[i].all.tags(tagName):elements[i].all;
    for(var j=0; j<result.length; j++) {
     node = result[j];
     if(classReg && !classReg.test(node.className)) continue;
     nodes[nodes.length] = node;
    }
   }
  
   return nodes;
}
</script>


您可能還喜歡看看這些: