📄 mask.js
字号:
line. Returns a number between 0 and 1
*/
function pixelFraction(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 = new Array(1);
var yvalues = new Array(1);
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
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)
}
}
/* classRounded End */
//var ps = GetPageSize();ps.PageW;ps.PageH;ps.WinW;ps.WinH;
classMask.getPageSize=function() {
var scrW, scrH;
if(window.innerHeight && window.scrollMaxY)
{ // Mozilla
scrW = window.innerWidth + window.scrollMaxX;
scrH = window.innerHeight + window.scrollMaxY;
} else if(document.body.scrollHeight > document.body.offsetHeight){
// all but IE Mac
scrW = document.body.scrollWidth;
scrH = document.body.scrollHeight;
} else if(document.body) {
// IE Mac
scrW = document.body.offsetWidth;
scrH = document.body.offsetHeight;
}
var winW, winH;
if(window.innerHeight) { // all except IE
winW = window.innerWidth;
winH = window.innerHeight;
} else if (document.documentElement && document.documentElement.clientHeight) {
// IE 6 Strict Mode
winW = document.documentElement.clientWidth;
winH = document.documentElement.clientHeight;
} else if (document.body) {
// other
winW = document.body.clientWidth;
winH = document.body.clientHeight;
}
//for small pages with total size less then the viewport
var pageW = (scrW<winW) ? winW : scrW;
var pageH = (scrH<winH) ? winH : scrH;
return {PageW:pageW, PageH:pageH, WinW:winW, WinH:winH};
}
//var ps = GetPageScroll();ps.X;ps.Y
classMask.getPageScroll=function() {
var x, y;
if(window.pageYOffset) {
// all except IE
y = window.pageYOffset;
x = window.pageXOffset;
} else if(document.documentElement && document.documentElement.scrollTop) {
//IE 6 Strict
y = document.documentElement.scrollTop;
x = document.documentElement.scrollLeft;
} else if (document.body) {
// all other IE
y = document.body.scrollTop;
x = document.body.scrollLeft;
} return {X:x, Y:y};
}
/* checked Explorer version Class */
classMask.Browser = {
init: function () {
this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
this.version = this.searchVersion(navigator.userAgent)
|| this.searchVersion(navigator.appVersion)
|| "an unknown version";
this.OS = this.searchString(this.dataOS) || "an unknown OS";
},
searchString: function (data) {
for (var i=0;i<data.length;i++) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -