是个图层,通过onmouseover事件调用
解决方案 »
- ajax 中多次传值 无法返回
- JS数组弹出页面的问题,请教
- js 提交页面会报错
- 修改<input type="file">的外观
- 用javascript写了个类,操作异步XMLHTTP的onreadystatechange时怎么取得类this指针
- 如何让ie执行脚本,不弹阻止脚本执行的提示条?
- javascript变量与java变量相互付值的问题
- 高手帮忙呀(Soft Keyboard)
- javascript如何打开一个word文件,怎么判断文件是否存在?
- showModelessDialog最低的支持版本是多少?
- 用a标签调用javascript方法,代码怎么写
- 在我的表单里面有 好几个输入框的名字都相同 如何在servlet中取出?
return "string" == typeof id ? document.getElementById(id) : id;
};function Event(e){
var oEvent = document.all ? window.event : e;
if (document.all) {
if(oEvent.type == "mouseout") {
oEvent.relatedTarget = oEvent.toElement;
}else if(oEvent.type == "mouseover") {
oEvent.relatedTarget = oEvent.fromElement;
}
}
return oEvent;
}function addEventHandler(oTarget, sEventType, fnHandler) {
if (oTarget.addEventListener) {
oTarget.addEventListener(sEventType, fnHandler, false);
} else if (oTarget.attachEvent) {
oTarget.attachEvent("on" + sEventType, fnHandler);
} else {
oTarget["on" + sEventType] = fnHandler;
}
};function Each(list, fun){
for (var i = 0, len = list.length; i < len; i++) { fun(list[i], i); }
};
var Class = {
create: function() {
return function() {
this.initialize.apply(this, arguments);
}
}
}Object.extend = function(destination, source) {
for (var property in source) {
destination[property] = source[property];
}
return destination;
}
var AlertBox = Class.create();
AlertBox.prototype = {
//
initialize: function(box, options) { var oThis = this;
this._touch = null;
this.Box = $(box);
this._timerShow = null;
this._timerHide = null;
this.SetOptions(options);
this.Delay = parseInt(this.options.Delay) || 0;
this.onShow = this.options.onShow;
this.Box.style.position = "absolute";
this.Box.style.visibility = "hidden";
addEventHandler(this.Box, "mouseover", function(){ oThis.Show(oThis._touch); })
addEventHandler(this.Box, "mouseout", function(e){ oThis.preHide(e); })
},
//设置默认属性
SetOptions: function(options) {
this.options = {//默认值
Delay: 300,//延时
onShow: function(){}//显示时执行
};
Object.extend(this.options, options || {});
},
//准备显示
preShow: function(touch) {
clearTimeout(this._timerHide); clearTimeout(this._timerShow);
var oThis = this; this._timerShow = setTimeout(function(){ oThis.Show(touch); }, this.Delay);
},
//显示
Show: function(touch) {
clearTimeout(this._timerHide); clearTimeout(this._timerShow);
this.onShow();
touch._onshow();
var o = touch, iLeft = o.offsetLeft, iTop = o.offsetTop;
this._touch = o;
iTop += o.offsetHeight;
iLeft -= this.Box.offsetWidth/2 - o.offsetWidth/2;
while (o.offsetParent) { o = o.offsetParent; iLeft += o.offsetLeft; iTop += o.offsetTop; }
this.Box.style.left = iLeft + "px";
this.Box.style.top = iTop + "px";
this.Box.style.visibility = "visible";
},
//准备隐藏
preHide: function(e) {
var oT = Event(e).relatedTarget;
if(!(this.Box.contains ? this.Box.contains(oT) || this.Box == oT : this.Box.compareDocumentPosition(oT) & 16)){
clearTimeout(this._timerHide); clearTimeout(this._timerShow);
var oThis = this; this._timerHide = setTimeout(function(){ oThis.Hide(); }, this.Delay);
}
},
//隐藏
Hide: function(e) {
clearTimeout(this._timerHide); clearTimeout(this._timerShow);
this.Box.style.visibility = "hidden";
//显示select
Each(document.getElementsByTagName("select"), function(o){ o.style.visibility = "visible"; });
},
//添加触发对象
Add: function(touch, onshow) {
var o = $(touch), oThis = this;
o._onshow = onshow || function(){};
addEventHandler(o, "mouseover", function(){ oThis.preShow(o); })
addEventHandler(o, "click", function(){ oThis.Show(o); })
addEventHandler(o, "mouseout", function(e){ oThis.preHide(e); })
}
};
var ab = new AlertBox("idBox");
ab.Add(o, function(){
o.innerHTML = "ref";
})
改div可以设置背景图片,背景颜色,等效果