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

📄 cvi_glossy_lib.js

📁 javascript实现很不错的图片的水晶效果
💻 JS
📖 第 1 页 / 共 2 页
字号:
/** * cvi_glossy_lib.js 1.2 (16-Jan-2008) * (c) by Christian Effenberger  * All Rights Reserved * Source: corner.netzgesta.de * Distributed under Netzgestade Software License Agreement * http://www.netzgesta.de/cvi/LICENSE.txt * License permits free of charge * use on non-commercial and  * private web sites only  * syntax:	cvi_glossy.defaultRadius = 25;		//INT 10-50 (%)	cvi_glossy.defaultColor = 0;		//STR '#000000'-'#ffffff' or 0	cvi_glossy.defaultColor2 = 0;		//STR '#000000'-'#ffffff' or 0	cvi_glossy.defaultGradient = 'v';	//STR  'd|h|v'-'diagonally|horizontal|vertical'	cvi_glossy.defaultShade = 50;		//INT 20-66 (% opacity)	cvi_glossy.defaultShadow = 40;		//INT 0-100 (% opacity)	cvi_glossy.defaultNoshadow = false;	//BOOLEAN	cvi_glossy.defaultNoradius = false;	//BOOLEAN	cvi_glossy.remove( image );	cvi_glossy.add( image, options );	cvi_glossy.modify( image, options );	cvi_glossy.add( image, { radius: value, color: value, color2: value, gradient: value, shadow: value, shade: value, noshadow: value, noradius: value } );	cvi_glossy.modify( image, { radius: value, color: value, color2: value, gradient: value, shadow: value, shade: value, noshadow: value, noradius: value } ); ***/function roundedRect(ctx,x,y,width,height,radius,nopath){	if (!nopath) ctx.beginPath();	ctx.moveTo(x,y+radius);	ctx.lineTo(x,y+height-radius);	ctx.quadraticCurveTo(x,y+height,x+radius,y+height);	ctx.lineTo(x+width-radius,y+height);	ctx.quadraticCurveTo(x+width,y+height,x+width,y+height-radius);	ctx.lineTo(x+width,y+radius);	ctx.quadraticCurveTo(x+width,y,x+width-radius,y);	ctx.lineTo(x+radius,y);	ctx.quadraticCurveTo(x,y,x,y+radius);	if (!nopath) ctx.closePath();}function addRadialStyle(ctx,x1,y1,r1,x2,y2,r2,opacity) {	var tmp = ctx.createRadialGradient(x1,y1,r1,x2,y2,r2);	var opt = Math.min(parseFloat(opacity+0.1),1.0);	tmp.addColorStop(0,'rgba(0,0,0,'+opt+')');	tmp.addColorStop(0.25,'rgba(0,0,0,'+opacity+')');	tmp.addColorStop(1,'rgba(0,0,0,0)');	return tmp;}function addLinearStyle(ctx,x,y,w,h,opacity) {	var tmp = ctx.createLinearGradient(x,y,w,h);	var opt = Math.min(parseFloat(opacity+0.1),1.0);	tmp.addColorStop(0,'rgba(0,0,0,'+opt+')');	tmp.addColorStop(0.25,'rgba(0,0,0,'+opacity+')');	tmp.addColorStop(1,'rgba(0,0,0,0)');	return tmp;}function addBright(ctx,x,y,width,height,radius,opacity) {	var style = ctx.createLinearGradient(0,y,0,y+height);	style.addColorStop(0,'rgba(254,254,254,'+opacity+')');	style.addColorStop(1,'rgba(254,254,254,0.1)');	ctx.beginPath(); ctx.moveTo(x,y+radius); ctx.lineTo(x,y+height-radius);	ctx.quadraticCurveTo(x,y+height,x+radius,y+height); ctx.lineTo(x+width-radius,y+height);	ctx.quadraticCurveTo(x+width,y+height,x+width,y+height-radius);	ctx.lineTo(x+width,y+radius); ctx.quadraticCurveTo(x+width,y,x+width-radius,y);	ctx.lineTo(x+radius,y); ctx.quadraticCurveTo(x,y,x,y+radius); ctx.closePath();	ctx.fillStyle = style; ctx.fill();}function addDark(ctx,x,y,width,height,radius,opacity) {	var style = ctx.createLinearGradient(0,y,0,y+height);	style.addColorStop(0,'rgba(0,0,0,0)');	style.addColorStop(1,'rgba(0,0,0,'+opacity+')');	ctx.beginPath(); ctx.moveTo(x,y); ctx.lineTo(x,y+height-radius);	ctx.quadraticCurveTo(x,y+height,x+radius,y+height); ctx.lineTo(x+width-radius,y+height);	ctx.quadraticCurveTo(x+width,y+height,x+width,y+height-radius);	ctx.lineTo(x+width,y); ctx.lineTo(x,y); ctx.closePath();	ctx.fillStyle = style; ctx.fill();}function addFrame(ctx,x,y,width,height,radius,opacity) {	roundedRect(ctx,x,y,width,height,radius);	var style = ctx.createLinearGradient(0,0,0,height);	style.addColorStop(0,'rgba(254,254,254,'+opacity+')');	style.addColorStop(1,'rgba(0,0,0,'+opacity+')');	ctx.lineWidth = (radius+x)/2;	ctx.strokeStyle = style;	ctx.stroke();}function glossyShadow(ctx,x,y,width,height,radius,opacity){	var style; var os = radius/2;	ctx.beginPath(); ctx.rect(x+radius,y,width-(radius*2),y+os); ctx.closePath();	style = addLinearStyle(ctx,x+radius,y+os,x+radius,y,opacity);	ctx.fillStyle = style; ctx.fill();	ctx.beginPath(); ctx.rect(x,y,radius,radius); ctx.closePath();	style = addRadialStyle(ctx,x+radius,y+radius,radius-os,x+radius,y+radius,radius,opacity);	ctx.fillStyle = style; ctx.fill();	ctx.beginPath(); ctx.rect(x,y+radius,os,height-(radius*2)); ctx.closePath();	style = addLinearStyle(ctx,x+os,y+radius,x,y+radius,opacity);	ctx.fillStyle = style; ctx.fill();	ctx.beginPath(); ctx.rect(x,y+height-radius,radius,radius); ctx.closePath();	style = addRadialStyle(ctx,x+radius,y+height-radius,radius-os,x+radius,y+height-radius,radius,opacity);	ctx.fillStyle = style; ctx.fill();	ctx.beginPath(); ctx.rect(x+radius,y+height-os,width-(radius*2),os); ctx.closePath();	style = addLinearStyle(ctx,x+radius,y+height-os,x+radius,y+height,opacity);	ctx.fillStyle = style; ctx.fill();	ctx.beginPath(); ctx.rect(x+width-radius,y+height-radius,radius,radius); ctx.closePath();	style = addRadialStyle(ctx,x+width-radius,y+height-radius,radius-os,x+width-radius,y+height-radius,radius,opacity);	ctx.fillStyle = style; ctx.fill();	ctx.beginPath(); ctx.rect(x+width-os,y+radius,os,height-(radius*2)); ctx.closePath();	style = addLinearStyle(ctx,x+width-os,y+radius,x+width,y+radius,opacity);	ctx.fillStyle = style; ctx.fill();	ctx.beginPath(); ctx.rect(x+width-radius,y,radius,radius); ctx.closePath();	style = addRadialStyle(ctx,x+width-radius,y+radius,radius-os,x+width-radius,y+radius,radius,opacity);	ctx.fillStyle = style; ctx.fill();}var cvi_glossy = {	defaultRadius : 25,	defaultColor : 0,	defaultColor2 : 0,	defaultGradient : 'v',	defaultShade : 50,	defaultShadow : 40,	defaultNoshadow : false,	defaultNoradius : false,	add: function(image, options) {		if(image.tagName.toUpperCase() == "IMG") {			var defopts = { "radius" : cvi_glossy.defaultRadius, "color" : cvi_glossy.defaultColor, "color2" : cvi_glossy.defaultColor2, "gradient" : cvi_glossy.defaultGradient, "shadow" : cvi_glossy.defaultShadow, "shade" : cvi_glossy.defaultShade, "noshadow" : cvi_glossy.defaultNoshadow, "noradius" : cvi_glossy.defaultNoradius }			if(options) {				for(var i in defopts) { if(!options[i]) { options[i] = defopts[i]; }}			}else {				options = defopts;			}			var imageWidth  = ('iwidth'  in options) ? parseInt(options.iwidth)  : image.width;			var imageHeight = ('iheight' in options) ? parseInt(options.iheight) : image.height;			try {				var object = image.parentNode; 				if(document.all && document.namespaces && !window.opera) {					if(document.namespaces['v'] == null) {						var stl = document.createStyleSheet();						stl.addRule("v\\:*", "behavior: url(#default#VML);"); 						document.namespaces.add("v", "urn:schemas-microsoft-com:vml");					}					var display = (image.currentStyle.display.toLowerCase()=='block')?'block':'inline-block';        					var canvas = document.createElement(['<var style="zoom:1;overflow:hidden;display:'+display+';width:'+imageWidth+'px;height:'+imageHeight+'px;padding:0;">'].join(''));					var flt =  image.currentStyle.styleFloat.toLowerCase();					display = (flt=='left'||flt=='right')?'inline':display;					canvas.options = options;					canvas.dpl = display;					canvas.id = image.id;					canvas.alt = image.alt;					canvas.title = image.title;

⌨️ 快捷键说明

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