/* 该文件是从网上收集的方法,用来做开关灯的,相对于原来的程序做了一些改变,兼容了ie10 */ var offlights = { create: function() { return function() { this.initialize.apply(this, arguments) } } } var overlay = offlights.create(); overlay.prototype = { initialize: function(options) { this.setoptions(options); this.browser = (function(ua){ var a=new object(); var b = { msie: /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) }; var 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.ie = b.msie; b.ie6 = b.msie && parseint(b.version, 10) == 6; b.ie7 = b.msie && parseint(b.version, 10) == 7; b.ie8 = b.msie && parseint(b.version, 10) == 8; a.b=vmark; a.v=b.version; return a; })(window.navigator.useragent.tolowercase()); this.isie = this.browser['b']=='msie' ? true : false; this.isie6 = (this.isie && this.browser['v']==6)?true:false; this._k_ = function(id) {return "string" == typeof id ? document.getelementbyid(id) : id}; this.lay = this._k_(this.options.lay) || document.body.insertbefore(document.createelement("div"), document.body.childnodes[0]); this.color = this.options.color; this.opacity = parseint(this.options.opacity); this.zindex = parseint(this.options.zindex); with(this.lay.style) { display = "none"; zindex = this.zindex; left = top = 0; position = "fixed"; width = height = "100%" } if (this.isie6) { this.lay.style.position = "absolute"; this._resize = this.bind(this, function() { this.lay.style.width = math.max(document.documentelement.scrollwidth, document.documentelement.clientwidth) + "px"; this.lay.style.height = math.max(document.documentelement.scrollheight, document.documentelement.clientheight) + "px" }); this.lay.innerhtml = '' } }, bind:function(object, fun) { return function() { return fun.apply(object, arguments) } }, extend :function(destination, source) { for (var property in source) { destination[property] = source[property] } }, setoptions: function(options) { this.options = { lay: null, color: "#000", opacity: 100, zindex: 50 }; this.extend(this.options, options || {}) }, show: function() { if (this.isie6) { this._resize(); window.attachevent("onresize", this._resize) } with(this.lay.style) { this.isie ? filter = "alpha(opacity:" + this.opacity + ")": opacity = this.opacity / 100; backgroundcolor = this.color; display = "block" } }, close: function() { this.lay.style.display = "none"; if (this.isie6) { window.detachevent("onresize", this._resize) } } }; var lightbox = offlights.create(); lightbox.prototype = { initialize: function(options) { this.overlay = new overlay(options); }, show: function(options) { this.overlay.show(); }, close: function() { this.overlay.close(); } };