📄 cvi_corner_lib.js
字号:
/** * cvi_corner_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_corner.defaultRadius = 0; //INT 0-100 (px) cvi_corner.defaultShadow = 0; //INT 0-100 (% opacity) cvi_corner.defaultShade = 0; //INT 0-100 (% opacity) cvi_corner.defaultInverse = false; //BOOLEAN cvi_corner.remove( image ); cvi_corner.add( image, options ); cvi_corner.modify( image, options ); cvi_corner.add( image, { radius: value, shadow: value, shade: value, inverse: value } ); cvi_corner.modify( image, { radius: value, shadow: value, shade: value, inverse: value } ); ***/function getRadius(radius,width,height){ var part = (Math.min(width,height)/100); radius = Math.max(Math.min(100,radius/part),0); return radius+'%';}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 addGradient(ctx,x,y,w,h,color,opacity) { var tmp = ctx.createLinearGradient(x,y,w,h); var val = (color!=0?0.25:0.35); tmp.addColorStop(0,'rgba('+color+','+color+','+color+',0.9)'); tmp.addColorStop(val,'rgba('+color+','+color+','+color+','+opacity+')'); tmp.addColorStop(0.75,'rgba('+color+','+color+','+color+',0)'); tmp.addColorStop(1,'rgba('+color+','+color+','+color+',0)'); return tmp;}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 addShine(ctx,width,height,radius,opacity,extra) { var style; var color = (extra!=1?254:0); style = addGradient(ctx,0,radius,radius,radius,color,opacity); ctx.beginPath(); ctx.moveTo(0,0); ctx.lineTo(0,height); ctx.lineTo(radius,height); ctx.lineTo(radius,radius); ctx.closePath(); ctx.fillStyle = style; ctx.fill(); style = addGradient(ctx,radius,0,radius,radius,color,opacity); ctx.beginPath(); ctx.moveTo(0,0); ctx.lineTo(width,0); ctx.lineTo(width,radius); ctx.lineTo(radius,radius); ctx.closePath(); ctx.fillStyle = style; ctx.fill();}function addShade(ctx,width,height,radius,opacity) { var style; style = addGradient(ctx,width,radius,width-radius,radius,0,opacity); ctx.beginPath(); ctx.moveTo(width,0); ctx.lineTo(width,height); ctx.lineTo(width-radius,height-radius); ctx.lineTo(width-radius,radius); ctx.closePath(); ctx.fillStyle = style; ctx.fill(); style = addGradient(ctx,radius,height,radius,height-radius,0,opacity); ctx.beginPath(); ctx.moveTo(width,height); ctx.lineTo(0,height); ctx.lineTo(radius,height-radius); ctx.lineTo(width-radius,height-radius); ctx.closePath(); ctx.fillStyle = style; ctx.fill();}function roundedShadow(ctx,x,y,width,height,radius,opacity){ var style; ctx.beginPath(); ctx.rect(x,y+height-radius,radius,radius); ctx.closePath(); style = addRadialStyle(ctx,x+radius,y+height-radius,radius-x,x+radius,y+height-radius,radius,opacity); ctx.fillStyle = style; ctx.fill(); ctx.beginPath(); ctx.rect(x+radius,y+height-y,width-x-(radius*2),y); ctx.closePath(); style = addLinearStyle(ctx,x+radius,y+height-y,x+radius,y+height,opacity); ctx.fillStyle = style; ctx.fill(); ctx.beginPath(); ctx.rect(width-radius,height-radius,radius+x,radius+y); ctx.closePath(); style = addRadialStyle(ctx,width-radius,height-radius,radius,width-radius,height-radius,radius+x,opacity); ctx.fillStyle = style; ctx.fill(); ctx.beginPath(); ctx.rect(x+width-x,y+radius,x,height-y-(radius*2)); ctx.closePath(); style = addLinearStyle(ctx,x+width-x,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-x,x+width-radius,y+radius,radius,opacity); ctx.fillStyle = style; ctx.fill();}var cvi_corner = { defaultRadius : 0, defaultShadow : 0, defaultShade : 0, defaultInverse : false, add: function(image, options) { if(image.tagName.toUpperCase() == "IMG") { var defopts = { "radius" : cvi_corner.defaultRadius, "shadow" : cvi_corner.defaultShadow, "shade" : cvi_corner.defaultShade, "inverse" : cvi_corner.defaultInverse } 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; canvas.source = image.src; canvas.className = image.className; canvas.style.cssText = image.style.cssText; canvas.height = imageHeight; canvas.width = imageWidth; object.replaceChild(canvas,image); cvi_corner.modify(canvas, options); }else { var canvas = document.createElement('canvas'); if(canvas.getContext("2d")) { canvas.options = options; canvas.id = image.id; canvas.alt = image.alt; canvas.title = image.title; canvas.source = image.src; canvas.className = image.className;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -