📄 rounded.js
字号:
// For each of the pixels that need anti aliasing between //the foreground/border colour & background draw single pixel divs this.drawPixel(intx, inty, outsideColour, (this.pixelFraction(intx, inty , j) * 100), 1, newCorner, ((this.borderWidth > 0)? 0 : -1), this.settings[cc].radius); } } } // END OF CORNER CREATION // ---------------------------------------------------- END // We now need to store the current corner in the masterConers array this.masterCorners[this.settings[cc].radius] = newCorner.cloneNode(true); } //Now we have a new corner we need to reposition all the pixels unless //the current corner is the bottom right. if(cc != "br") { // Loop through all children (pixel bars) for(var t = 0, k = newCorner.childNodes.length; t < k; t++) { // Get current pixel bar var pixelBar = newCorner.childNodes[t]; // Get current top and left properties var pixelBarTop = parseInt(pixelBar.style.top.substring(0, pixelBar.style.top.indexOf("px"))); var pixelBarLeft = parseInt(pixelBar.style.left.substring(0, pixelBar.style.left.indexOf("px"))); var pixelBarHeight = parseInt(pixelBar.style.height.substring(0, pixelBar.style.height.indexOf("px"))); // Reposition pixels if(cc == "tl" || cc == "bl") { pixelBar.style.left = this.settings[cc].radius -pixelBarLeft -1 + "px"; // Left } if(cc == "tr" || cc == "tl") { pixelBar.style.top = this.settings[cc].radius -pixelBarHeight -pixelBarTop + "px"; // Top } var value; switch(cc) { case "tr": value = (-1 *( Math.abs((this.boxWidth - this.settings[cc].radius + this.borderWidth) + pixelBarLeft) - (Math.abs(this.settings[cc].radius -pixelBarHeight -pixelBarTop - this.borderWidth)))); pixelBar.style.backgroundPosition = value + "px"; break; case "tl": value = (-1 *( Math.abs((this.settings[cc].radius -pixelBarLeft -1) - this.borderWidth) - (Math.abs(this.settings[cc].radius -pixelBarHeight -pixelBarTop - this.borderWidth)))); pixelBar.style.backgroundPosition = value + "px"; break; case "bl": value = (-1 *( Math.abs((this.settings[cc].radius -pixelBarLeft -1) - this.borderWidth) - (Math.abs((this.boxHeight + this.settings[cc].radius + pixelBarTop) -this.borderWidth)))); pixelBar.style.backgroundPosition = value + "px"; break; } } } } if(newCorner) { // Position the container switch(cc) { case "tl": if(newCorner.style.position == "absolute") newCorner.style.top = "0px"; if(newCorner.style.position == "absolute") newCorner.style.left = "0px"; if(this.topContainer) this.topContainer.appendChild(newCorner); break; case "tr": if(newCorner.style.position == "absolute") newCorner.style.top = "0px"; if(newCorner.style.position == "absolute") newCorner.style.right = "0px"; if(this.topContainer) this.topContainer.appendChild(newCorner); break; case "bl": if(newCorner.style.position == "absolute") newCorner.style.bottom = "0px"; if(newCorner.style.position == "absolute") newCorner.style.left = "0px"; if(this.bottomContainer) this.bottomContainer.appendChild(newCorner); break; case "br": if(newCorner.style.position == "absolute") newCorner.style.bottom = "0px"; if(newCorner.style.position == "absolute") newCorner.style.right = "0px"; if(this.bottomContainer) this.bottomContainer.appendChild(newCorner); break; } } } //The last thing to do is draw the rest of the filler DIVs. //We only need to create a filler DIVs when two corners have //diffrent radiuses in either the top or bottom container. // Find out which corner has the biiger radius and get the difference amount var radiusDiff = []; radiusDiff["t"] = this.settings.tl.enabled && this.settings.tr.enabled ? Math.abs(this.settings.tl.radius - this.settings.tr.radius) : 0; radiusDiff["b"] = this.settings.bl.enabled && this.settings.br.enabled ? Math.abs(this.settings.bl.radius - this.settings.br.radius) : 0; for(var z in radiusDiff) { if(radiusDiff[z]) { // Get the type of corner that is the smaller one var smallerCornerType = ((this.settings[z + "l"].radius < this.settings[z + "r"].radius)? z +"l" : z +"r"); // First we need to create a DIV for the space under the smaller corner var newFiller = document.createElement("DIV"); with(newFiller.style) { height = radiusDiff[z] + "px"; width = this.settings[smallerCornerType].radius+ "px" position = "absolute"; fontSize = "1px"; overflow = "hidden"; backgroundColor = this.boxColour; } // Position filler switch(smallerCornerType) { case "tl": with(newFiller.style) { bottom = "0px"; left = "0px"; borderLeft = this.borderString; } this.topContainer.appendChild(newFiller); break; case "tr": with(newFiller.style) { bottom = "0px"; right = "0px"; borderRight = this.borderString; } this.topContainer.appendChild(newFiller); break; case "bl": with(newFiller.style) { top = "0px"; left = "0px"; borderLeft = this.borderString; } this.bottomContainer.appendChild(newFiller); break; case "br": with(newFiller.style) { top = "0px"; right = "0px"; borderRight = this.borderString; } this.bottomContainer.appendChild(newFiller); break; } } // Create the bar to fill the gap between each corner horizontally var newFillerBar = document.createElement("DIV"); with(newFillerBar.style) { position = "relative"; fontSize = "1px"; overflow = "hidden"; backgroundColor = this.boxColour; } switch(z) { case "t": // Top Bar if(this.topContainer) { with(newFillerBar.style) { height = topMaxRadius - this.borderWidth + "px"; marginLeft = this.settings.tl.radius - this.borderWidth + "px"; marginRight = this.settings.tr.radius - this.borderWidth + "px"; borderTop = this.borderString; } this.topContainer.appendChild(newFillerBar); } break; case "b": if(this.bottomContainer) { // Bottom Bar with(newFillerBar.style) { height = botMaxRadius - this.borderWidth + "px"; marginLeft = this.settings.bl.radius - this.borderWidth + "px"; marginRight = this.settings.br.radius - this.borderWidth + "px"; borderBottom = this.borderString; } this.bottomContainer.appendChild(newFillerBar); } break; } } } // This function draws the pixles this.drawPixel = function(intx, inty, colour, transAmount, height, newCorner, image, cornerRadius) { // Create pixel var pixel = document.createElement("DIV"); // Section doesn't like with (pixel.style) { DEBUG? pixel.style.height = height + "px"; pixel.style.width = "1px"; pixel.style.position = "absolute"; pixel.style.fontSize = "1px"; pixel.style.overflow = "hidden"; // Dont apply background image to border pixels if(image == -1 && this.backgroundImage != "") { pixel.style.backgroundImage = this.backgroundImage; pixel.style.backgroundPosition = "-" + (this.boxWidth - (cornerRadius - intx) + this.borderWidth) + "px -" + ((this.boxHeight + cornerRadius + inty) -this.borderWidth) + "px"; } else { pixel.style.backgroundColor = colour; } // Set opacity if the transparency is anything other than 100 if (transAmount != 100) { dojo.style.setOpacity(pixel, transAmount); } // Set the pixels position pixel.style.top = inty + "px"; pixel.style.left = intx + "px"; newCorner.appendChild(pixel); } }, //For a pixel cut by the line determines the fraction of the pixel on the 'inside' of the //line. Returns a number between 0 and 1 pixelFraction: function(x, y, r) { var pixelfraction = 0; //determine the co-ordinates of the two points on the perimeter of the pixel that the //circle crosses var xvalues = []; var yvalues = []; var point = 0; var whatsides = ""; // x + 0 = Left var intersect = Math.sqrt((Math.pow(r,2) - Math.pow(x,2))); if ((intersect >= y) && (intersect < (y+1))) { whatsides = "Left"; xvalues[point] = 0; yvalues[point] = intersect - y; point = point + 1; } // y + 1 = Top var intersect = Math.sqrt((Math.pow(r,2) - Math.pow(y+1,2))); if ((intersect >= x) && (intersect < (x+1))) { whatsides = whatsides + "Top"; xvalues[point] = intersect - x; yvalues[point] = 1; point = point + 1; } // x + 1 = Right var intersect = Math.sqrt((Math.pow(r,2) - Math.pow(x+1,2))); if ((intersect >= y) && (intersect < (y+1))) { whatsides = whatsides + "Right"; xvalues[point] = 1; 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 rgb2Hex: function (rgbColour) { try{ // Get array of RGB values var rgbArray = this.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 = "#" + this.intToHex(red) + this.intToHex(green) + this.intToHex(blue); } catch(e){ alert("There was an error converting the RGB value to Hexadecimal in function rgb2Hex"); } return hexColour; }, //Converts a number to hexadecimal format intToHex: function (strNum) { var base = strNum / 16; var rem = strNum % 16; var base = base - (rem / 16); var baseS = this.makeHex(base); var remS = this.makeHex(rem); return baseS + '' + remS; }, //gets the hex bits of a number makeHex: function(x) { if((x >= 0) && (x <= 9)) { return x; } else { switch(x) { case 10: return "A"; case 11: return "B"; case 12: return "C"; case 13: return "D"; case 14: return "E"; case 15: return "F"; } } }, // Returns an array of rbg values rgb2Array: function(rgbColour) { // Remove rgb() var rgbValues = rgbColour.substring(4, rgbColour.indexOf(")")); // Split RGB into array var rgbArray = rgbValues.split(", "); return rgbArray; }}); // end function
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -