rounded_corners.inc.js
来自「PHP 知识管理系统(基于树结构的知识管理系统), 英文原版的PHP源码。」· JavaScript 代码 · 共 1,115 行 · 第 1/4 页
JS
1,115 行
yvalues[point] = intersect - y; point = point + 1; } // y + 0 = Bottom var intersect = Math.sqrt((Math.pow(r,2) - Math.pow(y,2))); if ((intersect >= x) && (intersect < (x+1))) { whatsides = whatsides + "Bottom"; xvalues[point] = intersect - x; yvalues[point] = 0; } /* depending on which sides of the perimeter of the pixel the circle crosses calculate the fraction of the pixel inside the circle */ switch (whatsides) { case "LeftRight": pixelfraction = Math.min(yvalues[0],yvalues[1]) + ((Math.max(yvalues[0],yvalues[1]) - Math.min(yvalues[0],yvalues[1]))/2); break; case "TopRight": pixelfraction = 1-(((1-xvalues[0])*(1-yvalues[1]))/2); break; case "TopBottom": pixelfraction = Math.min(xvalues[0],xvalues[1]) + ((Math.max(xvalues[0],xvalues[1]) - Math.min(xvalues[0],xvalues[1]))/2); break; case "LeftBottom": pixelfraction = (yvalues[0]*xvalues[1])/2; break; default: pixelfraction = 1; } return pixelfraction; } // This function converts CSS rgb(x, x, x) to hexadecimal function rgb2Hex(rgbColour) { try{ // Get array of RGB values var rgbArray = rgb2Array(rgbColour); // Get RGB values var red = parseInt(rgbArray[0]); var green = parseInt(rgbArray[1]); var blue = parseInt(rgbArray[2]); // Build hex colour code var hexColour = "#" + IntToHex(red) + IntToHex(green) + IntToHex(blue); } catch(e){ alert("There was an error converting the RGB value to Hexadecimal in function rgb2Hex"); } return hexColour; } // Returns an array of rbg values function rgb2Array(rgbColour) { // Remove rgb() var rgbValues = rgbColour.substring(4, rgbColour.indexOf(")")); // Split RGB into array var rgbArray = rgbValues.split(", "); return rgbArray; } /* Function by Simon Willison from sitepoint.com Modified by Cameron Cooke adding Safari's rgba support */ function setOpacity(obj, opacity) { opacity = (opacity == 100)?99.999:opacity; if(isSafari && obj.tagName != "IFRAME") { // Get array of RGB values var rgbArray = rgb2Array(obj.style.backgroundColor); // Get RGB values var red = parseInt(rgbArray[0]); var green = parseInt(rgbArray[1]); var blue = parseInt(rgbArray[2]); // Safari using RGBA support obj.style.backgroundColor = "rgba(" + red + ", " + green + ", " + blue + ", " + opacity/100 + ")"; } else if(typeof(obj.style.opacity) != "undefined") { // W3C obj.style.opacity = opacity/100; } else if(typeof(obj.style.MozOpacity) != "undefined") { // Older Mozilla obj.style.MozOpacity = opacity/100; } else if(typeof(obj.style.filter) != "undefined") { // IE obj.style.filter = "alpha(opacity:" + opacity + ")"; } else if(typeof(obj.style.KHTMLOpacity) != "undefined") { // Older KHTML Based Browsers obj.style.KHTMLOpacity = opacity/100; } } /* Returns index if the passed value is found in the array otherwise returns false. */ function inArray(array, value) { for(var i = 0; i < array.length; i++){ // Matches identical (===), not just similar (==). if (array[i] === value) return i; } return false; } /* Returns true if the passed value is found as a key in the array otherwise returns false. */ function inArrayKey(array, value) { for(key in array){ // Matches identical (===), not just similar (==). if(key === value) return true; } return false; } // Cross browser add event wrapper function addEvent(elm, evType, fn, useCapture) { if (elm.addEventListener) { elm.addEventListener(evType, fn, useCapture); return true; } else if (elm.attachEvent) { var r = elm.attachEvent('on' + evType, fn); return r; } else { elm['on' + evType] = fn; } } // Cross browser remove event wrapper function removeEvent(obj, evType, fn, useCapture){ if (obj.removeEventListener){ obj.removeEventListener(evType, fn, useCapture); return true; } else if (obj.detachEvent){ var r = obj.detachEvent("on"+evType, fn); return r; } else { alert("Handler could not be removed"); } } // Formats colours function format_colour(colour) { var returnColour = "#ffffff"; // Make sure colour is set and not transparent if(colour != "" && colour != "transparent") { // RGB Value? if(colour.substr(0, 3) == "rgb") { // Get HEX aquiv. returnColour = rgb2Hex(colour); } else if(colour.length == 4) { // 3 chr colour code add remainder returnColour = "#" + colour.substring(1, 2) + colour.substring(1, 2) + colour.substring(2, 3) + colour.substring(2, 3) + colour.substring(3, 4) + colour.substring(3, 4); } else { // Normal valid hex colour returnColour = colour; } } return returnColour; } // Returns the style value for the property specfied function get_style(obj, property, propertyNS) { try { if(obj.currentStyle) { var returnVal = eval("obj.currentStyle." + property); } else { /* Safari does not expose any information for the object if display is set to none is set so we temporally enable it. */ if(isSafari && obj.style.display == "none") { obj.style.display = ""; var wasHidden = true; } var returnVal = document.defaultView.getComputedStyle(obj, '').getPropertyValue(propertyNS); // Rehide the object if(isSafari && wasHidden) { obj.style.display = "none"; } } } catch(e) { // Do nothing } return returnVal; } // Get elements by class by Dustin Diaz. function getElementsByClass(searchClass, node, tag) { var classElements = new Array(); if(node == null) node = document; if(tag == null) tag = '*'; var els = node.getElementsByTagName(tag); var elsLen = els.length; var pattern = new RegExp("(^|\s)"+searchClass+"(\s|$)"); for (i = 0, j = 0; i < elsLen; i++) { if(pattern.test(els[i].className)) { classElements[j] = els[i]; j++; } } return classElements; } // Displays error message function newCurvyError(errorMessage) { return new Error("curvyCorners Error:\n" + errorMessage) }
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?