⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 svg.js

📁 这是一个ajax的例子大家好好的看看就是一个鱼眼的效果
💻 JS
📖 第 1 页 / 共 2 页
字号:
if(!dojo._hasResource["dojox.gfx.svg"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.dojo._hasResource["dojox.gfx.svg"] = true;dojo.provide("dojox.gfx.svg");dojo.require("dojox.gfx._base");dojo.require("dojox.gfx.shape");dojo.require("dojox.gfx.path");dojox.gfx.svg.xmlns = {	xlink: "http://www.w3.org/1999/xlink",	svg:   "http://www.w3.org/2000/svg"};dojox.gfx.svg.getRef = function(name){	// summary: returns a DOM Node specified by the name argument or null	// name: String: an SVG external reference 	if(!name || name == "none") return null;	if(name.match(/^url\(#.+\)$/)){		return dojo.byId(name.slice(5, -1));	// Node	}	// alternative representation of a reference	if(name.match(/^#dojoUnique\d+$/)){		// we assume here that a reference was generated by dojox.gfx		return dojo.byId(name.slice(1));	// Node	}	return null;	// Node};dojox.gfx.svg.dasharray = {	solid:				"none",	shortdash:			[4, 1],	shortdot:			[1, 1],	shortdashdot:		[4, 1, 1, 1],	shortdashdotdot:	[4, 1, 1, 1, 1, 1],	dot:				[1, 3],	dash:				[4, 3],	longdash:			[8, 3],	dashdot:			[4, 3, 1, 3],	longdashdot:		[8, 3, 1, 3],	longdashdotdot:		[8, 3, 1, 3, 1, 3]};dojo.extend(dojox.gfx.Shape, {	// summary: SVG-specific implementation of dojox.gfx.Shape methods		setFill: function(fill){		// summary: sets a fill object (SVG)		// fill: Object: a fill object		//	(see dojox.gfx.defaultLinearGradient, 		//	dojox.gfx.defaultRadialGradient, 		//	dojox.gfx.defaultPattern, 		//	or dojo.Color)		if(!fill){			// don't fill			this.fillStyle = null;			this.rawNode.setAttribute("fill", "none");			this.rawNode.setAttribute("fill-opacity", 0);			return this;		}		var f;		// FIXME: slightly magical. We're using the outer scope's "f", but setting it later		var setter = function(x){				// we assume that we're executing in the scope of the node to mutate				this.setAttribute(x, f[x].toFixed(8));			};		if(typeof(fill) == "object" && "type" in fill){			// gradient			switch(fill.type){				case "linear":					f = dojox.gfx.makeParameters(dojox.gfx.defaultLinearGradient, fill);					var gradient = this._setFillObject(f, "linearGradient");					dojo.forEach(["x1", "y1", "x2", "y2"], setter, gradient);					break;				case "radial":					f = dojox.gfx.makeParameters(dojox.gfx.defaultRadialGradient, fill);					var gradient = this._setFillObject(f, "radialGradient");					dojo.forEach(["cx", "cy", "r"], setter, gradient);					break;				case "pattern":					f = dojox.gfx.makeParameters(dojox.gfx.defaultPattern, fill);					var pattern = this._setFillObject(f, "pattern");					dojo.forEach(["x", "y", "width", "height"], setter, pattern);					break;			}			this.fillStyle = f;			return this;		}		// color object		var f = dojox.gfx.normalizeColor(fill);		this.fillStyle = f;		this.rawNode.setAttribute("fill", f.toCss());		this.rawNode.setAttribute("fill-opacity", f.a);		this.rawNode.setAttribute("fill-rule", "evenodd");		return this;	// self	},	setStroke: function(stroke){		// summary: sets a stroke object (SVG)		// stroke: Object: a stroke object		//	(see dojox.gfx.defaultStroke) 			if(!stroke){			// don't stroke			this.strokeStyle = null;			this.rawNode.setAttribute("stroke", "none");			this.rawNode.setAttribute("stroke-opacity", 0);			return this;		}		// normalize the stroke		if(typeof stroke == "string"){			stroke = {color: stroke};		}		var s = this.strokeStyle = dojox.gfx.makeParameters(dojox.gfx.defaultStroke, stroke);		s.color = dojox.gfx.normalizeColor(s.color);		// generate attributes		var rn = this.rawNode;		if(s){			rn.setAttribute("stroke", s.color.toCss());			rn.setAttribute("stroke-opacity", s.color.a);			rn.setAttribute("stroke-width",   s.width);			rn.setAttribute("stroke-linecap", s.cap);			if(typeof s.join == "number"){				rn.setAttribute("stroke-linejoin",   "miter");				rn.setAttribute("stroke-miterlimit", s.join);			}else{				rn.setAttribute("stroke-linejoin",   s.join);			}			var da = s.style.toLowerCase();			if(da in dojox.gfx.svg.dasharray){ da = dojox.gfx.svg.dasharray[da]; }			if(da instanceof Array){				da = dojo.clone(da);				for(var i = 0; i < da.length; ++i){					da[i] *= s.width;				}				if(s.cap != "butt"){					for(var i = 0; i < da.length; i += 2){						da[i] -= s.width;						if(da[i] < 1){ da[i] = 1; }					}					for(var i = 1; i < da.length; i += 2){						da[i] += s.width;					}				}				da = da.join(",");			}			rn.setAttribute("stroke-dasharray", da);			rn.setAttribute("dojoGfxStrokeStyle", s.style);		}		return this;	// self	},		_getParentSurface: function(){		var surface = this.parent;		for(; surface && !(surface instanceof dojox.gfx.Surface); surface = surface.parent);		return surface;	},	_setFillObject: function(f, nodeType){		var svgns = dojox.gfx.svg.xmlns.svg;		this.fillStyle = f;		var surface = this._getParentSurface(),			defs = surface.defNode,			fill = this.rawNode.getAttribute("fill"),			ref  = dojox.gfx.svg.getRef(fill);		if(ref){			fill = ref;			if(fill.tagName.toLowerCase() != nodeType.toLowerCase()){				var id = fill.id;				fill.parentNode.removeChild(fill);				fill = document.createElementNS(svgns, nodeType);				fill.setAttribute("id", id);				defs.appendChild(fill);			}else{				while(fill.childNodes.length){					fill.removeChild(fill.lastChild);				}			}		}else{			fill = document.createElementNS(svgns, nodeType);			fill.setAttribute("id", dojox.gfx._base._getUniqueId());			defs.appendChild(fill);		}		if(nodeType == "pattern"){			if(dojo.isSafari){				fill.setAttributeNS(null, "patternUnits", "userSpaceOnUse");			}else{				fill.setAttribute("patternUnits", "userSpaceOnUse");			}			var img = document.createElementNS(svgns, "image");			img.setAttribute("x", 0);			img.setAttribute("y", 0);			img.setAttribute("width",  f.width .toFixed(8));			img.setAttribute("height", f.height.toFixed(8));			img.setAttributeNS(dojox.gfx.svg.xmlns.xlink, "href", f.src);			fill.appendChild(img);		}else{			if(dojo.isSafari){				fill.setAttributeNS(null, "gradientUnits", "userSpaceOnUse");			}else{				fill.setAttribute("gradientUnits", "userSpaceOnUse");			}			for(var i = 0; i < f.colors.length; ++i){				var c = f.colors[i], t = document.createElementNS(svgns, "stop"),					cc = c.color = dojox.gfx.normalizeColor(c.color);				t.setAttribute("offset",       c.offset.toFixed(8));				t.setAttribute("stop-color",   cc.toCss());				t.setAttribute("stop-opacity", cc.a);				fill.appendChild(t);			}		}		this.rawNode.setAttribute("fill", "url(#" + fill.getAttribute("id") +")");		this.rawNode.removeAttribute("fill-opacity");		this.rawNode.setAttribute("fill-rule", "evenodd");		return fill;	},		_applyTransform: function() {		var matrix = this.matrix;		if(matrix){			var tm = this.matrix;			this.rawNode.setAttribute("transform", "matrix(" +				tm.xx.toFixed(8) + "," + tm.yx.toFixed(8) + "," +				tm.xy.toFixed(8) + "," + tm.yy.toFixed(8) + "," +				tm.dx.toFixed(8) + "," + tm.dy.toFixed(8) + ")");		}else{			this.rawNode.removeAttribute("transform");		}		return this;	},	setRawNode: function(rawNode){		// summary:		//	assigns and clears the underlying node that will represent this		//	shape. Once set, transforms, gradients, etc, can be applied.		//	(no fill & stroke by default)		var r = this.rawNode = rawNode;		r.setAttribute("fill", "none");		r.setAttribute("fill-opacity", 0);		r.setAttribute("stroke", "none");		r.setAttribute("stroke-opacity", 0);		r.setAttribute("stroke-width", 1);		r.setAttribute("stroke-linecap", "butt");		r.setAttribute("stroke-linejoin", "miter");		r.setAttribute("stroke-miterlimit", 4);	},		setShape: function(newShape){		// summary: sets a shape object (SVG)		// newShape: Object: a shape object		//	(see dojox.gfx.defaultPath,		//	dojox.gfx.defaultPolyline,		//	dojox.gfx.defaultRect,		//	dojox.gfx.defaultEllipse,		//	dojox.gfx.defaultCircle,		//	dojox.gfx.defaultLine,		//	or dojox.gfx.defaultImage)		this.shape = dojox.gfx.makeParameters(this.shape, newShape);		for(var i in this.shape){			if(i != "type"){ this.rawNode.setAttribute(i, this.shape[i]); }		}		return this;	// self	},	// move family	_moveToFront: function(){		// summary: moves a shape to front of its parent's list of shapes (SVG)		this.rawNode.parentNode.appendChild(this.rawNode);		return this;	// self	},	_moveToBack: function(){		// summary: moves a shape to back of its parent's list of shapes (SVG)		this.rawNode.parentNode.insertBefore(this.rawNode, this.rawNode.parentNode.firstChild);		return this;	// self	}});dojo.declare("dojox.gfx.Group", dojox.gfx.Shape, {	// summary: a group shape (SVG), which can be used 	//	to logically group shapes (e.g, to propagate matricies)	constructor: function(){		dojox.gfx.svg.Container._init.call(this);	},	setRawNode: function(rawNode){		// summary: sets a raw SVG node to be used by this shape		// rawNode: Node: an SVG node		this.rawNode = rawNode;	}});dojox.gfx.Group.nodeType = "g";dojo.declare("dojox.gfx.Rect", dojox.gfx.shape.Rect, {	// summary: a rectangle shape (SVG)	setShape: function(newShape){		// summary: sets a rectangle shape object (SVG)		// newShape: Object: a rectangle shape object		this.shape = dojox.gfx.makeParameters(this.shape, newShape);		this.bbox = null;		for(var i in this.shape){			if(i != "type" && i != "r"){ this.rawNode.setAttribute(i, this.shape[i]); }		}		if(this.shape.r){			this.rawNode.setAttribute("ry", this.shape.r);			this.rawNode.setAttribute("rx", this.shape.r);		}		return this;	// self	}});dojox.gfx.Rect.nodeType = "rect";dojox.gfx.Ellipse = dojox.gfx.shape.Ellipse;dojox.gfx.Ellipse.nodeType = "ellipse";dojox.gfx.Circle = dojox.gfx.shape.Circle;dojox.gfx.Circle.nodeType = "circle";dojox.gfx.Line = dojox.gfx.shape.Line;dojox.gfx.Line.nodeType = "line";

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -