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

📄 svg.js

📁 这是一个ajax的例子大家好好的看看就是一个鱼眼的效果
💻 JS
📖 第 1 页 / 共 2 页
字号:
dojo.declare("dojox.gfx.Polyline", dojox.gfx.shape.Polyline, {	// summary: a polyline/polygon shape (SVG)	setShape: function(points, closed){		// summary: sets a polyline/polygon shape object (SVG)		// points: Object: a polyline/polygon shape object		if(points && points instanceof Array){			// branch			// points: Array: an array of points			this.shape = dojox.gfx.makeParameters(this.shape, { points: points });			if(closed && this.shape.points.length){ 				this.shape.points.push(this.shape.points[0]);			}		}else{			this.shape = dojox.gfx.makeParameters(this.shape, points);		}		this.box = null;		var attr = [], p = this.shape.points;		for(var i = 0; i < p.length; ++i){			if(typeof p[i] == "number"){				attr.push(p[i].toFixed(8));			}else{				attr.push(p[i].x.toFixed(8));				attr.push(p[i].y.toFixed(8));			}		}		this.rawNode.setAttribute("points", attr.join(" "));		return this;	// self	}});dojox.gfx.Polyline.nodeType = "polyline";dojo.declare("dojox.gfx.Image", dojox.gfx.shape.Image, {	// summary: an image (SVG)	setShape: function(newShape){		// summary: sets an image shape object (SVG)		// newShape: Object: an image shape object		this.shape = dojox.gfx.makeParameters(this.shape, newShape);		this.bbox = null;		var rawNode = this.rawNode;		for(var i in this.shape){			if(i != "type" && i != "src"){ rawNode.setAttribute(i, this.shape[i]); }		}		rawNode.setAttributeNS(dojox.gfx.svg.xmlns.xlink, "href", this.shape.src);		return this;	// self	}});dojox.gfx.Image.nodeType = "image";dojo.declare("dojox.gfx.Text", dojox.gfx.shape.Text, {	// summary: an anchored text (SVG)	setShape: function(newShape){		// summary: sets a text shape object (SVG)		// newShape: Object: a text shape object		this.shape = dojox.gfx.makeParameters(this.shape, newShape);		this.bbox = null;		var r = this.rawNode, s = this.shape;		r.setAttribute("x", s.x);		r.setAttribute("y", s.y);		r.setAttribute("text-anchor", s.align);		r.setAttribute("text-decoration", s.decoration);		r.setAttribute("rotate", s.rotated ? 90 : 0);		r.setAttribute("kerning", s.kerning ? "auto" : 0);		r.setAttribute("text-rendering", "optimizeLegibility");		r.textContent = s.text;		return this;	// self	},	getTextWidth: function(){ 		// summary: get the text width in pixels 		var rawNode = this.rawNode,			oldParent = rawNode.parentNode,			_measurementNode = rawNode.cloneNode(true); 		_measurementNode.style.visibility = "hidden"; 		// solution to the "orphan issue" in FF 		var _width = 0, _text = _measurementNode.firstChild.nodeValue; 		oldParent.appendChild(_measurementNode); 		// solution to the "orphan issue" in Opera 		// (nodeValue == "" hangs firefox) 		if(_text!=""){ 			while(!_width){ 				_width = parseInt(_measurementNode.getBBox().width); 			} 		} 		oldParent.removeChild(_measurementNode); 		return _width; 	} });dojox.gfx.Text.nodeType = "text";dojo.declare("dojox.gfx.Path", dojox.gfx.path.Path, {	// summary: a path shape (SVG)	_updateWithSegment: function(segment){		// summary: updates the bounding box of path with new segment		// segment: Object: a segment		dojox.gfx.Path.superclass._updateWithSegment.apply(this, arguments);		if(typeof(this.shape.path) == "string"){			this.rawNode.setAttribute("d", this.shape.path);		}	},	setShape: function(newShape){		// summary: forms a path using a shape (SVG)		// newShape: Object: an SVG path string or a path object (see dojox.gfx.defaultPath)		dojox.gfx.Path.superclass.setShape.apply(this, arguments);		this.rawNode.setAttribute("d", this.shape.path);		return this;	// self	}});dojox.gfx.Path.nodeType = "path";dojo.declare("dojox.gfx.TextPath", dojox.gfx.path.TextPath, {	// summary: a textpath shape (SVG)	_updateWithSegment: function(segment){		// summary: updates the bounding box of path with new segment		// segment: Object: a segment		dojox.gfx.Path.superclass._updateWithSegment.apply(this, arguments);		this._setTextPath();	},	setShape: function(newShape){		// summary: forms a path using a shape (SVG)		// newShape: Object: an SVG path string or a path object (see dojox.gfx.defaultPath)		dojox.gfx.Path.superclass.setShape.apply(this, arguments);		this._setTextPath();		return this;	// self	},	_setTextPath: function(){		if(typeof this.shape.path != "string"){ return; }		var r = this.rawNode;		if(!r.firstChild){			var tp = document.createElementNS(dojox.gfx.svg.xmlns.svg, "textPath"),				tx = document.createTextNode("");			tp.appendChild(tx);			r.appendChild(tp);		}		var ref  = r.firstChild.getAttributeNS(dojox.gfx.svg.xmlns.xlink, "href"),			path = ref && dojox.gfx.svg.getRef(ref);		if(!path){			var surface = this._getParentSurface();			if(surface){				var defs = surface.defNode;				path = document.createElementNS(dojox.gfx.svg.xmlns.svg, "path");				var id = dojox.gfx._base._getUniqueId();				path.setAttribute("id", id);				defs.appendChild(path);				r.firstChild.setAttributeNS(dojox.gfx.svg.xmlns.xlink, "href", "#" + id);			}		}		if(path){			path.setAttribute("d", this.shape.path);		}	},	_setText: function(){		var r = this.rawNode;		if(!r.firstChild){			var tp = document.createElementNS(dojox.gfx.svg.xmlns.svg, "textPath"),				tx = document.createTextNode("");			tp.appendChild(tx);			r.appendChild(tp);		}		r = r.firstChild;		var t = this.text;		r.setAttribute("alignment-baseline", "middle");		switch(t.align){			case "middle":				r.setAttribute("text-anchor", "middle");				r.setAttribute("startOffset", "50%");				break;			case "end":				r.setAttribute("text-anchor", "end");				r.setAttribute("startOffset", "100%");				break;			default:				r.setAttribute("text-anchor", "start");				r.setAttribute("startOffset", "0%");				break;		}		//r.parentNode.setAttribute("alignment-baseline", "central");		//r.setAttribute("dominant-baseline", "central");		r.setAttribute("baseline-shift", "0.5ex");		r.setAttribute("text-decoration", t.decoration);		r.setAttribute("rotate", t.rotated ? 90 : 0);		r.setAttribute("kerning", t.kerning ? "auto" : 0);		r.firstChild.data = t.text;	}});dojox.gfx.TextPath.nodeType = "text";dojo.declare("dojox.gfx.Surface", dojox.gfx.shape.Surface, {	// summary: a surface object to be used for drawings (SVG)	constructor: function(){		dojox.gfx.svg.Container._init.call(this);	},	setDimensions: function(width, height){		// summary: sets the width and height of the rawNode		// width: String: width of surface, e.g., "100px"		// height: String: height of surface, e.g., "100px"		if(!this.rawNode){ return this; }		this.rawNode.setAttribute("width",  width);		this.rawNode.setAttribute("height", height);		return this;	// self	},	getDimensions: function(){		// summary: returns an object with properties "width" and "height"		return this.rawNode ? {width: this.rawNode.getAttribute("width"), height: this.rawNode.getAttribute("height")} : null; // Object	}});dojox.gfx.createSurface = function(parentNode, width, height){	// summary: creates a surface (SVG)	// parentNode: Node: a parent node	// width: String: width of surface, e.g., "100px"	// height: String: height of surface, e.g., "100px"	var s = new dojox.gfx.Surface();	s.rawNode = document.createElementNS(dojox.gfx.svg.xmlns.svg, "svg");	s.rawNode.setAttribute("width",  width);	s.rawNode.setAttribute("height", height);	var node = document.createElementNS(dojox.gfx.svg.xmlns.svg, "defs"); 	s.rawNode.appendChild(node);	s.defNode = node;		dojo.byId(parentNode).appendChild(s.rawNode);	return s;	// dojox.gfx.Surface};// Extendersdojox.gfx.svg.Font = {	_setFont: function(){		// summary: sets a font object (SVG)		var f = this.fontStyle;		// next line doesn't work in Firefox 2 or Opera 9		//this.rawNode.setAttribute("font", dojox.gfx.makeFontString(this.fontStyle));		this.rawNode.setAttribute("font-style", f.style);		this.rawNode.setAttribute("font-variant", f.variant);		this.rawNode.setAttribute("font-weight", f.weight);		this.rawNode.setAttribute("font-size", f.size);		this.rawNode.setAttribute("font-family", f.family);	}};dojox.gfx.svg.Container = {	_init: function(){		dojox.gfx.shape.Container._init.call(this);	},	add: function(shape){		// summary: adds a shape to a group/surface		// shape: dojox.gfx.Shape: an VML shape object		if(this != shape.getParent()){			this.rawNode.appendChild(shape.rawNode);			//dojox.gfx.Group.superclass.add.apply(this, arguments);			//this.inherited(arguments);			dojox.gfx.shape.Container.add.apply(this, arguments);		}		return this;	// self	},	remove: function(shape, silently){		// summary: remove a shape from a group/surface		// shape: dojox.gfx.Shape: an VML shape object		// silently: Boolean?: if true, regenerate a picture		if(this == shape.getParent()){			if(this.rawNode == shape.rawNode.parentNode){				this.rawNode.removeChild(shape.rawNode);			}			//dojox.gfx.Group.superclass.remove.apply(this, arguments);			//this.inherited(arguments);			dojox.gfx.shape.Container.remove.apply(this, arguments);		}		return this;	// self	},	clear: function(){		// summary: removes all shapes from a group/surface		var r = this.rawNode;		while(r.lastChild){			r.removeChild(r.lastChild);		}		var d = this.defNode;		if(d){			while(d.lastChild){				d.removeChild(d.lastChild);			}			r.appendChild(d);		}		//return this.inherited(arguments);	// self		return dojox.gfx.shape.Container.clear.apply(this, arguments);	},	_moveChildToFront: dojox.gfx.shape.Container._moveChildToFront,	_moveChildToBack:  dojox.gfx.shape.Container._moveChildToBack};dojo.mixin(dojox.gfx.shape.Creator, {	// summary: SVG shape creators	createObject: function(shapeType, rawShape){		// summary: creates an instance of the passed shapeType class		// shapeType: Function: a class constructor to create an instance of		// rawShape: Object: properties to be passed in to the classes "setShape" method		if(!this.rawNode){ return null; }		var shape = new shapeType(),			node = document.createElementNS(dojox.gfx.svg.xmlns.svg, shapeType.nodeType); 		shape.setRawNode(node);		this.rawNode.appendChild(node);		shape.setShape(rawShape);		this.add(shape);		return shape;	// dojox.gfx.Shape	}});dojo.extend(dojox.gfx.Text, dojox.gfx.svg.Font);dojo.extend(dojox.gfx.TextPath, dojox.gfx.svg.Font);dojo.extend(dojox.gfx.Group, dojox.gfx.svg.Container);dojo.extend(dojox.gfx.Group, dojox.gfx.shape.Creator);dojo.extend(dojox.gfx.Surface, dojox.gfx.svg.Container);dojo.extend(dojox.gfx.Surface, dojox.gfx.shape.Creator);}

⌨️ 快捷键说明

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