跨帧结构无限级菜单
解释地址
写点东西不容易啊 真的就这么杯具了 杯具啊
杯具的菜单
body{margin:0px; padding:0px; font-size:12px;}
*{margin:0; padding:0;}
.de{ background-image:url(http://paui.52done.cn/demos/menu/images/nav_bg.gif);}
#demo1{list-style:none; height:26px; cursor:pointer; background-image:url(http://paui.52done.cn/demos/menu/images/nav_bg.gif); color:#FFFFFF; margin-left:20px;}
#demo1 li{float:left; height:25px; line-height:25px; padding:0 15px; margin-top:1px;}
#demo1 li.focus{ color:#FE6100; background-color:#fcfcfc;}
- 人族
- 兽族
- 不死族
(function(window,undefined){
window.Sys = function (ua){
var b = {
ie: /msie/.test(ua) && !/opera/.test(ua),
opera: /opera/.test(ua),
safari: /webkit/.test(ua) && !/chrome/.test(ua),
firefox: /firefox/.test(ua),
chrome: /chrome/.test(ua)
},vMark = "";
for (var i in b) {
if (b[i]) { vMark = "safari" == i ? "version" : i; break; }
}
b.version = vMark && RegExp("(?:" + vMark + ")[\\/: ]([\\d.]+)").test(ua) ? RegExp.$1 : "0";
b.ie6 = b.ie && parseInt(b.version, 10) == 6;
b.ie7 = b.ie && parseInt(b.version, 10) == 7;
b.ie8 = b.ie && parseInt(b.version, 10) == 8;
return b;
}(window.navigator.userAgent.toLowerCase());
window.Sys.ie6&&document.execCommand("BackgroundImageCache", false, true);
window.$ = function(Id){
return document.getElementById(Id);
};
window.addListener = function(element,e,fn){
!element.events&&(element.events = {});
element.events[e]&&(element.events[e][addListener.guid++]=fn)||(element.events[e] = {'0':fn});
element.addEventListener?element.addEventListener(e,fn,false):element.attachEvent("on" + e,fn);
};
window.addListener.guid = 1;
window.removeListener = function(element,e,fn){
var handlers = element.events[e],type;
if(fn){
for(type in handlers)
if(handlers[type]===fn){
element.removeEventListener?element.removeEventListener(e,fn,false):element.detachEvent("on" + e,fn);
delete handlers[type];
}
}else{
for(type in handlers){
element.removeEventListener?element.removeEventListener(e,handlers[type],false):element.detachEvent("on" + e,handlers[type]);
delete handlers[type];
}
}
};
window.setStyle = function(elems, style, value){
if( !elems.length ) elems = [elems];
if( typeof style == "string"){
style = value === undefined?{cssText:style}:(function(o){
return (o[style] = value,o);
})({});
};
each(elems,function(i,elem,style){
var value,name,ie=Sys.ie ;
for(name in style){
value = style[name];
if (name === "opacity" && ie) {
elem.style.filter = (elem.currentStyle.filter || "").replace( /alpha\([^)]*\)/, "" ) + "alpha(opacity=" + value * 100 + ")";
}else if(name === "float"){
elem.style[ ie ? "styleFloat" : "cssFloat" ] = value;
}else{
name = name.replace(/-([a-z])/ig, function(all, letter){
return letter.toUpperCase();
});
elem.style[name] = value;
}
}
},style);
};
var slice = Array.prototype.slice;
window.Bind = function(object, fun) {
var args = slice.call(arguments).slice(2);
return function() {
return fun.apply(object, args);
};
};
window.BindAsEventListener = function(object, fun,args) {
var args = slice.call(arguments).slice(2);
return function(event) {
return fun.apply(object, [event || window.event].concat(args));
}
};
//copy from jQ
window.extend = function(){
var target = arguments[0] || {}, i = 1, length = arguments.length, deep = true, options;
if ( typeof target === "boolean" ) {
deep = target;
target = arguments[1] || {};
i = 2;
}
if ( typeof target !== "object" && Object.prototype.toString.call(target)!="[object Function]")
target = {};
for(;i"+menu.txt+"
";
});
var cul = cDoc.getElementsByTagName('ul')[0];
//第一次的时候生成ul 之后就一直用之前的ul
if(cul){
cul.innerHTML = str;
//为什么要删除事件了 因为一只都是用的 一个popup 但是参数不同 所以只要删除后重新绑定 来跟新数据
removeListener(cul,'mouseover');
removeListener(cul,'mouseout');
removeListener(cul,'click');
}else{
//一样要添加样式 本页面的样式是去不到的 因为popup本身也相当于一个页面
var style=cDoc.createStyleSheet();
style.addRule('ul',this.style.ul);
style.addRule('ul li',this.style.li);
style.addRule('ul li.focus',this.style.focus);
cDoc.body.innerHTML = "
- "+str+"
";
cul = cDoc.getElementsByTagName('ul')[0];
}
popup&&popup.hide();
//显示的位置和大小
if(this.ul===ul){
var ret = objPos(li);
popup.show(ret.left+1,ret.top+li.offsetHeight,140,data.length*22+2,cDoc.body);
}else{
popup.show(140-2,22*num,140,data.length*22+2,cDoc.body);
}
//把显示出来的 popup放到this.list中 如果已经添加了 就不要重复添加了
this.findul(cul)?(this.findul(cul).obj.is=false):this.list.push({ul:cul,is:false});
addListener(cul,'mouseover',BindAsEventListener(this,this.openPopup,cul,cDoc,data));
addListener(cul,'click',BindAsEventListener(this,this.reUrl));
addListener(cul,'mouseout',BindAsEventListener(this,this.hidea,this.ul,cul));
}
},
reUrl : function(e){
if(e.srcElement.nodeName.toLowerCase() ==='li')
alert(e.srcElement.getAttribute('pa_ui_menuie_url'))
},
clear : function(){
clearTimeout(this.time);
this.time = null;
},
hidea : function(e,ul,cul){
var li = e.srcElement,self=this,callback=this.findul(cul||'');
if(!cul){
this.isOver = false;
this.list.length>0&&this.list[0].is===true?this.foucsLi.push(li):removeClass(li,'focus');
}else{
var i=callback.id+1,l=this.list.length,p=false;
for(;i
[Ctrl+A 全选 注:如需引入外部Js需刷新才能执行]