


Full-screen js avatar upload plug-in source code HD version_javascript skills
The example in this article shares the full-screen js avatar upload plug-in source code for your reference. The specific content is as follows
index.html
<!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width" /> <title>ccp</title> <link href="Content/ccp.css" rel="stylesheet" /> <script src="Scripts/cxc.js"></script> <script src="Scripts/ccp.js"></script> <script src="Scripts/fun.js"></script> </head> <body> <div id="SelectPicture">选 择 图 片</div> <div id="pre"> <div id="prea"> <div id="ctna"> <img id="imga"/ alt="Full-screen js avatar upload plug-in source code HD version_javascript skills" > </div> </div> <div id="preb"> <div id="ctnb"> <img id="imgb"/ alt="Full-screen js avatar upload plug-in source code HD version_javascript skills" > </div> </div> <div id="prec"> <div id="ctnc"> <img id="imgc"/ alt="Full-screen js avatar upload plug-in source code HD version_javascript skills" > </div> </div> </div> <div id="ccp"> <div id="ctn"> <img id="fixed_img" / alt="Full-screen js avatar upload plug-in source code HD version_javascript skills" > <div id="varied_div"> <img id="varied_div_img" / alt="Full-screen js avatar upload plug-in source code HD version_javascript skills" > <i id="TopLeft"></i> <i id="TopRight"></i> <i id="BottomRight"></i> <i id="BottomLeft"></i> </div> </div> <div id="black_cover"></div> </div> <div id="bt"> <div id="Y_OUT"> <div id="Y">Y</div> </div> <div id="N_OUT"> <div id="N">N</div> </div> </div> </body> </html>
cxc.js
/* cxc.js 频繁操作公共接口 */ var $ = function (id) { return document.getElementById(id); }; //通过id获取dom对象 var A = function (msg) { alert(msg); }; //alert的简写 var EmptyFun = function () { }; // 空方法 var setL = function (dom, L) { dom.style.left = L + "px"; }; // 设置 dom 的 left var setT = function (dom, T) { dom.style.top = T + "px"; }; // 设置 dom 的 top var setLT = function (dom, L, T) { dom.style.left = L + "px"; dom.style.top = T + "px"; }; //同时设置 dom 的 left top var getLT = function (dom) { return [parseInt(dom.style.left), parseInt(dom.style.top)]; }; // 返回dom的left和top值,类型为整型数组[int,int] var setW = function (W) { dom.style.width = W + "px"; }; // 设置 dom 的 width var setH = function (H) { dom.style.height = H + "px"; }; // 设置 dom 的 height var setWH = function (dom, W, H) { dom.style.width = W + "px"; dom.style.height = H + "px"; }; //同时设置 dom 的 width height var getWH = function (dom) { return [parseInt(dom.style.width), parseInt(dom.style.height)]; }; // 返回dom的 width 和 height 值,类型为整型数组[int,int] var setLTWH = function (dom, L, T, W, H) { dom.style.left = L + "px"; dom.style.top = T + "px"; dom.style.width = W + "px"; dom.style.height = H + "px"; }; //同时设置 dom 的 left top width height var setRTWH = function (dom, R, T, W, H) { dom.style.right = R + "px"; dom.style.top = T + "px"; dom.style.width = W + "px"; dom.style.height = H + "px"; }; //同时设置 dom 的 left top width height var getLTWH = function (dom) { return [parseInt(dom.style.left), parseInt(dom.style.top), parseInt(dom.style.width), parseInt(dom.style.height)] }; // 返回dom的 left top width height 值,类型为整型数组[int,int,int,int] var setcursor = function (dom,shape) { dom.style.cursor = shape; }; //设置鼠标经过dom的指针形状 var EventsType = {//事件类型 click:"click", mousedown:"mousedown", mouseup:"mouseup", mouseover:"mouseover", mouseleave:"mouseleave", mousemove:"mousemove", DOMContentLoaded:"DOMContentLoaded", }; var AddEvent = function (dom, type, fun) { dom.addEventListener(type, fun, false); }; //添加dom对象的事件监听方法 var AddEvent2 = function (dom, type1, fun1, type2, fun2) { dom.addEventListener(type1, fun1, false); dom.addEventListener(type2, fun2, false); }; //一次添加dom的两个事件监听方法 var AddEvent3 = function (dom, type1, fun1, type2, fun2, type3, fun3) { dom.addEventListener(type1, fun1, false); dom.addEventListener(type2, fun2, false); dom.addEventListener(type3, fun3, false); }; //一次添加dom的三个事件监听方法 var DelEvent = function (dom, type, fun) { dom.removeEventListener(type, fun, false); }; // 删除dom对象的事件监听方法 var DelEvent2 = function (dom, type1, fun1, type2, fun2) { dom.removeEventListener(type1, fun1, false); dom.removeEventListener(type2, fun2, false); }; //一次删除dom对象的两个事件监听方法 var DelEvent3 = function (dom, type1, fun1, type2, fun2, type3, fun3) { dom.removeEventListener(type1, fun1, false); dom.removeEventListener(type2, fun2, false); dom.removeEventListener(type3, fun3, false); }; //一次删除dom对象的三个事件监听方法 var inArray = function (str, arr) { for (var i = 0; i < arr.length; i++) { if (str == arr[i]) { return true; } } return false; }; // 判断字符串str是否存在于数组arr var cannotselect = function () { window.getSelection().removeAllRanges(); }; //页面元素(文字、图片等)不能被选中 var setStyle = function (dom, styleName, styleValue) { dom.setAttribute("style", styleName + ":" + styleValue + ";"); }; //设置dom的 一个style 属性值 var setStyle2 = function (dom, styleName1, styleValue1, styleName2, styleValue2) { dom.setAttribute("style", styleName1 + ":" + styleValue1 + ";" + styleName2 + ":" + styleValue2 + ";"); };//一次设置dom的 两个style 属性值 var delStyle = function (dom, styleName) { dom.removeAttribute("style", styleName); };//删除dom的 一个style 属性值 var delStyle2 = function (dom, styleName1, styleName2) { dom.removeAttribute("style", styleName1); dom.removeAttribute("style", styleName2); };//一次删除dom的 两个style 属性值 var setAttr = function (dom, attrName, attrValue) { dom.setAttribute(attrName, attrValue); };// 设置dom的 一个属性值 var setAttr2 = function (dom, attrName1, attrValue1, attrName2, attrValue2) { dom.setAttribute(attrName1, attrValue1); dom.setAttribute(attrName2, attrValue2); };//一次设置dom的 两个属性值 var delAttr = function (dom, attrName) { dom.removeAttribute(attrName); };//删除dom的 一个属性值 var delAttr2 = function (dom, attrName1, attrName2) { dom.removeAttribute(attrName1); dom.removeAttribute(attrName2); };//删除dom 的两个属性值 var Hide = function (dom) { dom.style.display = "none"; };// 隐藏dom var Hide3 = function (dom1,dom2,dom3) { dom1.style.display = "none"; dom2.style.display = "none"; dom3.style.display = "none"; };// 隐藏3个dom var Show = function (dom) { dom.style.display = "inline"; }; // 显示dom var Show3 = function (dom1, dom2, dom3) { dom1.style.display = "inline"; dom2.style.display = "inline"; dom3.style.display = "inline"; };// 显示3个dom /* cxc.js 频繁操作公共接口 */ /* AJAX 接口 */ var url, method, msg; var xmlReq = new XMLHttpRequest(); var AJAX = function (url, method, msg, callback) { xmlReq.open(method, url, true); xmlReq.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); xmlReq.onreadystatechange = function () { if (xmlReq.readyState == 4) { if (xmlReq.status == 200) { callback(); } else { A("ajax status is " + xmlReq.status); } } }; xmlReq.send(msg); }; /* AJAX 接口 */ /* 入口 */ var start = function (fun) { var begin = function () { DelEvent(document, EventsType.DOMContentLoaded, begin); fun(); }; AddEvent(document, EventsType.DOMContentLoaded, begin); }; /* 入口 */ /* 环境 */ var screenW = window.innerWidth; var screenH = window.innerHeight; /* 环境 */
ccp.js
var cfg = { imgtype: ["image/jpeg", "image/png", "image/gif", "image/bmp"], imgsize: 5 * 1024 * 1024, varied_divMIN: 50, varied_divDEFAULT: 100, needWH:0, }; var dom = { body: null, SelectPicture: null, upfile: null, pre: null, ccp: null, bt: null, prea: null, preb: null, prec: null, ctna: null, ctnb: null, ctnc: null, imga: null, imgb: null, imgc: null, Y_OUT: null, N_OUT: null, Y: null, N: null, ctn: null, black_cover: null, fixed_img: null, varied_div: null, varied_div_img: null, TopLeft: null, TopRight: null, BottomRight: null, BottomLeft: null, }; var ccp = { SelectPictureW: null, SelectPictureH: null, SelectPictureP1: 9, SelectPictureP2: 4, SelectPictureL: null, SelectPictureT: null, SelectPictureFontSize: null, /////////////////////////// file: null, imgtype: null, imgsize: null, /////////////////////////// imgW: null, imgH: null, imgN: null, imgURL: null, ////////////////////////// preW: null, preH: null, ccpW: null, ccpH: null, btW: null, btH: null, ///////////////////////// pre4: null, preaL: null, preaT: null, preaWH: null, prebL: null, prebT: null, prebWH: null, precL: null, precT: null, precWH: null, ctnLT: 3, ctnaWH: null, ctnbWH: null, ctncWH: null, ////////////////////////// YN3: null, YN_OUTWH: null, YNWH: null, YN_OUTR: null, Y_OUTT: null, N_OUTT: null, YNLT1: 25, YNLT2: 20, ////////////////////////// ctnL: null, ctnT: null, black_coverL: null, black_coverT: null, ///////////////////////// varied_divL: null, varied_divT: null, varied_divWH: null, varied_divMaxL: null, varied_divMaxT: null, varied_div_imgWH: null, varied_div_imgL: null, varied_div_imgT: null, ///////////////////////// imgaW: null, imgaH: null, imgaL: null, imgaT: null, imgbW: null, imgbH: null, imgbL: null, imgbT: null, imgcW: null, imgcH: null, imgcL: null, imgcT: null, ///////////////////////// }; var GET_DOM = function () { dom.body = document.body; dom.pre = $("pre"); dom.ccp = $("ccp"); dom.bt = $("bt"); dom.SelectPicture = $("SelectPicture"); dom.prea = $("prea"); dom.preb = $("preb"); dom.prec = $("prec"); dom.ctna = $("ctna"); dom.ctnb = $("ctnb"); dom.ctnc = $("ctnc"); dom.imga = $("imga"); dom.imgb = $("imgb"); dom.imgc = $("imgc"); dom.Y_OUT = $("Y_OUT"); dom.N_OUT = $("N_OUT"); dom.Y = $("Y"); dom.N = $("N"); dom.ctn = $("ctn"); dom.black_cover = $("black_cover"); dom.fixed_img = $("fixed_img"); dom.varied_div = $("varied_div"); dom.varied_div_img = $("varied_div_img"); dom.TopLeft = $("TopLeft"); dom.TopRight = $("TopRight"); dom.BottomRight = $("BottomRight"); dom.BottomLeft = $("BottomLeft"); }; var INIT_DOM = function () { setStyle2(dom.body, "width", screenW + "px", "height", screenH + "px"); dom.body.style.backgroundImage = get_random_bgimg(7);///////////////////// set_SelectPictureW(Math.floor(screenW / ccp.SelectPictureP1)); AddEvent2(dom.SelectPicture, EventsType.mouseover, SelectPicture_mouseover, EventsType.mouseleave, SelectPicture_mouseleave); AddEvent(dom.SelectPicture, EventsType.click, SelectPicture_click);///////////////////// ccp.preH = ccp.ccpH = ccp.btH = screenH - 2; ccp.ccpW = screenH + 100 - 2; ccp.preW = Math.ceil((screenW - (ccp.ccpW + 2)) / 2) - 2; ccp.btW = screenW - (ccp.ccpW + 2) - (ccp.preW + 2) - 2; setStyle2(dom.pre, "width", ccp.preW + "px", "height", ccp.preH + "px"); setStyle2(dom.ccp, "width", ccp.ccpW + "px", "height", ccp.ccpH + "px"); setStyle2(dom.bt, "width", ccp.btW + "px", "height", ccp.btH + "px"); Hide3(dom.pre, dom.ccp, dom.bt);///////////////////// }; var EVENTS = function () { AddEvent(dom.varied_div, EventsType.mousedown, varied_div_mousedown);//varied_div AddEvent(dom.TopLeft, EventsType.mousedown, TopLeft_mousedown);//TopLeft AddEvent(dom.TopRight, EventsType.mousedown, TopRight_mousedown);//TopRight AddEvent(dom.BottomRight, EventsType.mousedown, BottomRight_mousedown);//BottomRight AddEvent(dom.BottomLeft, EventsType.mousedown, BottomLeft_mousedown);//BottomLeft AddEvent(dom.Y, EventsType.click, Y_click);//Y AddEvent(dom.N, EventsType.click, N_click);//N }; var END = function () { AddEvent(document, EventsType.mousemove, cannotselect); }; start(function () { GET_DOM(); INIT_DOM(); EVENTS(); END(); });
fun.js
var get_random_bgimg = function (n) { var m = Math.floor(Math.random() * n); var r = "url(Images/bg" + 6 + ".png)"; return r; }; var set_SelectPictureW = function (W) { ccp.SelectPictureW = W; ccp.SelectPictureH = Math.floor(ccp.SelectPictureW / ccp.SelectPictureP2); ccp.SelectPictureL = Math.floor((screenW - ccp.SelectPictureW) / 2); ccp.SelectPictureT = Math.floor((screenH - ccp.SelectPictureH) / 2); ccp.SelectPictureFontSize = Math.floor(ccp.SelectPictureH / 1.5); setStyle(dom.SelectPicture, "font-size", ccp.SelectPictureFontSize + "px"); setLTWH(dom.SelectPicture, ccp.SelectPictureL, ccp.SelectPictureT, ccp.SelectPictureW, ccp.SelectPictureH); }; var SelectPicture_mouseover = function () { set_SelectPictureW(ccp.SelectPictureW + 15); }; var SelectPicture_mouseleave = function () { set_SelectPictureW(ccp.SelectPictureW - 15); }; /////////////////////////////////////////////////// var downX, downY, oldL, oldT, tempWH, tempL, tempT, dxMax, tempMaxL, tempMaxT; var varied_divLimit = function () { if (ccp.varied_divL < 0) ccp.varied_divL = 0; else if (ccp.varied_divL > ccp.varied_divMaxL) ccp.varied_divL = ccp.varied_divMaxL; if ((ccp.varied_divT < 0)) ccp.varied_divT = 0; else if (ccp.varied_divT > ccp.varied_divMaxT) ccp.varied_divT = ccp.varied_divMaxT; }; var varied_div_mousedown = function (e) { if (e.button > 0) { varied_div_mouseup(); return false; } e.preventDefault && e.preventDefault(); downX = e.clientX; downY = e.clientY; oldL = ccp.varied_divL; oldT = ccp.varied_divT; AddEvent2(document, EventsType.mouseup, varied_div_mouseup, EventsType.mousemove, doc_varied_div_mousemove); }; var doc_varied_div_mousemove = function (e) { ccp.varied_divL = oldL + e.clientX - downX; ccp.varied_divT = oldT + e.clientY - downY; varied_divLimit(); setLT(dom.varied_div, ccp.varied_divL, ccp.varied_divT); setvaried_div_img(); setpreimg(); }; var varied_div_mouseup = function () { DelEvent2(document, EventsType.mouseup, varied_div_mouseup, EventsType.mousemove, doc_varied_div_mousemove); }; //////////////////////////////////////////////////// var TopLeft_mousedown = function (e) { if (e.button > 0) { TopLeft_mouseup(); return false; } e.preventDefault && e.preventDefault(); downX = e.clientX; downY = e.clientY; oldL = ccp.varied_divL; oldT = ccp.varied_divT; tempWH = ccp.varied_divWH; tempL = ccp.varied_divL; tempT = ccp.varied_divT; tempMaxL = ccp.varied_divMaxL; tempMaxT = ccp.varied_divMaxT; dxMax = tempL >= tempT ? tempT : tempL; AddEvent2(document, EventsType.mouseup, TopLeft_mouseup, EventsType.mousemove, doc_TopLeft_mousemove); }; var doc_TopLeft_mousemove = function (e) { varied_div_mouseup();//移动事件屏蔽,非常重要 var dx = e.clientY - downY; if (dx < 0 && Math.abs(dx) > dxMax) { dx = -dxMax; } else if (dx > 0 && dx > tempWH - cfg.varied_divMIN) { dx = tempWH - cfg.varied_divMIN; } ccp.varied_divMaxL = tempMaxL + dx; ccp.varied_divMaxT = tempMaxT + dx; ccp.varied_divL = oldL + dx; ccp.varied_divT = oldT + dx; ccp.varied_divWH = tempWH - dx; setLTWH(dom.varied_div, ccp.varied_divL, ccp.varied_divT, ccp.varied_divWH, ccp.varied_divWH); setvaried_div_img(); setpreimg(); }; var TopLeft_mouseup = function () { DelEvent2(document, EventsType.mouseup, TopLeft_mouseup, EventsType.mousemove, doc_TopLeft_mousemove); }; //////////////////////////////////////////////////// var TopRight_mousedown = function (e) { if (e.button > 0) { TopRight_mouseup(); return false; } e.preventDefault && e.preventDefault(); downX = e.clientX; downY = e.clientY; oldL = ccp.varied_divL; oldT = ccp.varied_divT; tempWH = ccp.varied_divWH; tempL = ccp.imgW - ccp.varied_divL - ccp.varied_divWH; tempT = ccp.varied_divT; tempMaxL = ccp.varied_divMaxL; tempMaxT = ccp.varied_divMaxT; dxMax = tempL >= tempT ? tempT : tempL; AddEvent2(document, EventsType.mouseup, TopRight_mouseup, EventsType.mousemove, doc_TopRight_mousemove); }; var doc_TopRight_mousemove = function (e) { varied_div_mouseup();//移动事件屏蔽,非常重要 var dx = e.clientY - downY; if (dx < 0 && Math.abs(dx) > dxMax) { dx = -dxMax; } else if (dx > 0 && dx > tempWH - cfg.varied_divMIN) { dx = tempWH - cfg.varied_divMIN; } ccp.varied_divMaxL = tempMaxL + dx; ccp.varied_divMaxT = tempMaxT + dx; ccp.varied_divL = oldL; ccp.varied_divT = oldT + dx; ccp.varied_divWH = tempWH - dx; setLTWH(dom.varied_div, ccp.varied_divL, ccp.varied_divT, ccp.varied_divWH, ccp.varied_divWH); setvaried_div_img(); setpreimg(); }; var TopRight_mouseup = function () { DelEvent2(document, EventsType.mouseup, TopRight_mouseup, EventsType.mousemove, doc_TopRight_mousemove); }; /////////////////////////////////////////////////// var BottomRight_mousedown = function (e) { if (e.button > 0) { BottomRight_mouseup(); return false; } e.preventDefault && e.preventDefault(); downX = e.clientX; downY = e.clientY; oldL = ccp.varied_divL; oldT = ccp.varied_divT; tempWH = ccp.varied_divWH; tempL = ccp.imgW - ccp.varied_divL - ccp.varied_divWH; tempT = ccp.imgH - ccp.varied_divT - ccp.varied_divWH; tempMaxL = ccp.varied_divMaxL; tempMaxT = ccp.varied_divMaxT; dxMax = tempL >= tempT ? tempT : tempL; AddEvent2(document, EventsType.mouseup, BottomRight_mouseup, EventsType.mousemove, doc_BottomRight_mousemove); }; var doc_BottomRight_mousemove = function (e) { varied_div_mouseup();//移动事件屏蔽,非常重要 var dx = e.clientY - downY; if (dx > 0 && dx > dxMax) { dx = dxMax; } else if (dx < 0 && Math.abs(dx) > tempWH - cfg.varied_divMIN) { dx = -(tempWH - cfg.varied_divMIN); } ccp.varied_divMaxL = tempMaxL - dx; ccp.varied_divMaxT = tempMaxT - dx; ccp.varied_divL = oldL; ccp.varied_divT = oldT; ccp.varied_divWH = tempWH + dx; setLTWH(dom.varied_div, ccp.varied_divL, ccp.varied_divT, ccp.varied_divWH, ccp.varied_divWH); setvaried_div_img(); setpreimg(); }; var BottomRight_mouseup = function () { DelEvent2(document, EventsType.mouseup, BottomRight_mouseup, EventsType.mousemove, doc_BottomRight_mousemove); }; /////////////////////////////////////////////////// var BottomLeft_mousedown = function (e) { if (e.button > 0) { BottomLeft_mouseup(); return false; } e.preventDefault && e.preventDefault(); downX = e.clientX; downY = e.clientY; oldL = ccp.varied_divL; oldT = ccp.varied_divT; tempWH = ccp.varied_divWH; tempL = ccp.varied_divL; tempT = ccp.imgH - ccp.varied_divT - ccp.varied_divWH; tempMaxL = ccp.varied_divMaxL; tempMaxT = ccp.varied_divMaxT; dxMax = tempL >= tempT ? tempT : tempL; AddEvent2(document, EventsType.mouseup, BottomLeft_mouseup, EventsType.mousemove, doc_BottomLeft_mousemove); }; var doc_BottomLeft_mousemove = function (e) { varied_div_mouseup();//移动事件屏蔽,非常重要 var dx = e.clientY - downY; if (dx > 0 && dx > dxMax) { dx = dxMax; } else if (dx < 0 && Math.abs(dx) > tempWH - cfg.varied_divMIN) { dx = -(tempWH - cfg.varied_divMIN); } ccp.varied_divMaxL = tempMaxL - dx; ccp.varied_divMaxT = tempMaxT - dx; ccp.varied_divL = oldL - dx; ccp.varied_divT = oldT; ccp.varied_divWH = tempWH + dx; setLTWH(dom.varied_div, ccp.varied_divL, ccp.varied_divT, ccp.varied_divWH, ccp.varied_divWH); setvaried_div_img(); setpreimg(); }; var BottomLeft_mouseup = function () { DelEvent2(document, EventsType.mouseup, BottomLeft_mouseup, EventsType.mousemove, doc_BottomLeft_mousemove); }; /////////////////////////////////////////////////// var getDATA = function () { var parameter = location.search; //获取url中"?"符后的字串 if (parameter.length == 0) { return 666; } else { var ss = parameter.split("&"); url = ss[0].split("=")[1]; cfg.needWH = ss[1].split("=")[1]; } if (url.length == 0) { return 777; } else if (cfg.needWH == 0) { return 888; } else if (cfg.needWH > 1000) { return 999; } var canvas = document.createElement("canvas"); canvas.style.display = "none"; var ctx = canvas.getContext("2d"); ctx.fillStyle = "#FFFFFF"; canvas.width = canvas.height = cfg.needWH; ctx.fillRect(0, 0, cfg.needWH, cfg.needWH); var a = Math.ceil(ccp.varied_divL * ccp.imgN); var b = Math.ceil(ccp.varied_divT * ccp.imgN); var c = Math.ceil(ccp.varied_divWH * ccp.imgN); ctx.drawImage(dom.fixed_img, a, b, c, c, 0, 0, cfg.needWH, cfg.needWH); return canvas.toDataURL(ccp.imgtype, 1); }; var callback = function () { var txt = xmlReq.responseText; alert(txt); window.opener = null; window.open('', '_self'); window.close(); }; var Y_click = function () { var DATA = getDATA(); DATA == 666 && alert("没有参数"); DATA == 777 && alert("没有返回地址"); DATA == 888 && alert("未给出返回图片大小"); DATA == 999 && alert("图片大小不能超过 1000 X 1000"); if (DATA == 666 || DATA == 777 || DATA == 888 || DATA == 999) { window.opener = null; window.open('', '_self'); window.close(); }//没有参数或参数错误关闭页面 method = "post"; msg = ""; AJAX(url, method, "DATA=" + DATA, callback); }; var N_click = function () { Hide3(dom.pre, dom.ccp, dom.bt); }; /////////////////////////////////////////////////// var check_imgtype = function () { if (!inArray(ccp.imgtype, cfg.imgtype)) { alert("请选择正确的图片类型"); return false; } else { return true; } }; var check_imgsize = function () { if (ccp.imgsize > cfg.imgsize) { alert("图片不能超过"+(cfg.imgsize/1024)/1024+"M"); return false; } else { return true; } }; var set_pre = function () { ccp.preaWH = Math.round(ccp.preW * 0.6); ccp.prebWH = Math.round(ccp.preW * 0.5); ccp.precWH = Math.round(ccp.preW * 0.4); ccp.preaL = Math.round((ccp.preW - ccp.preaWH) / 2); ccp.prebL = Math.round((ccp.preW - ccp.prebWH) / 2); ccp.precL = Math.round((ccp.preW - ccp.precWH) / 2); ccp.pre4 = Math.round((ccp.preH - ccp.preaWH - ccp.prebWH - ccp.precWH) / 4); ccp.preaT = ccp.pre4; ccp.prebT = ccp.pre4 * 2 + ccp.preaWH; ccp.precT = ccp.pre4 * 3 + ccp.preaWH + ccp.prebWH; setLTWH(dom.prea, ccp.preaL, ccp.preaT, ccp.preaWH, ccp.preaWH); setLTWH(dom.preb, ccp.prebL, ccp.prebT, ccp.prebWH, ccp.prebWH); setLTWH(dom.prec, ccp.precL, ccp.precT, ccp.precWH, ccp.precWH); //////////////////////////////////////////////////////////////// ccp.ctnaWH = ccp.preaWH - ccp.ctnLT * 2; ccp.ctnbWH = ccp.prebWH - ccp.ctnLT * 2; ccp.ctncWH = ccp.precWH - ccp.ctnLT * 2; setLTWH(dom.ctna, ccp.ctnLT, ccp.ctnLT, ccp.ctnaWH, ccp.ctnaWH); setLTWH(dom.ctnb, ccp.ctnLT, ccp.ctnLT, ccp.ctnbWH, ccp.ctnbWH); setLTWH(dom.ctnc, ccp.ctnLT, ccp.ctnLT, ccp.ctncWH, ccp.ctncWH); dom.imga.src = dom.imgb.src = dom.imgc.src = ccp.imgURL; }; var setYN = function (dom, n) { ccp.YNWH = ccp.YN_OUTWH - n * 2; setStyle(dom, "font-size", Math.floor(ccp.YNWH * 0.9) + "px"); setLTWH(dom, n, n, ccp.YNWH, ccp.YNWH); }; var Y_mouseover = function () { setYN(dom.Y, ccp.YNLT2); }; var Y_mouseleave = function () { setYN(dom.Y, ccp.YNLT1); }; var N_mouseover = function () { setYN(dom.N, ccp.YNLT2); }; var N_mouseleave = function () { setYN(dom.N, ccp.YNLT1); }; var set_bt = function () { ccp.YN_OUTWH = Math.round(ccp.btW * 0.6); ccp.YN_OUTR = Math.round((ccp.btW - ccp.YN_OUTWH) / 2); ccp.YN3 = Math.round((ccp.btH - ccp.YN_OUTWH * 2) / 3); ccp.Y_OUTT = ccp.YN3; ccp.N_OUTT = ccp.YN3 * 2 + ccp.YN_OUTWH; setRTWH(dom.Y_OUT, ccp.YN_OUTR, ccp.Y_OUTT, ccp.YN_OUTWH, ccp.YN_OUTWH); setRTWH(dom.N_OUT, ccp.YN_OUTR, ccp.N_OUTT, ccp.YN_OUTWH, ccp.YN_OUTWH); setYN(dom.Y, ccp.YNLT1); setYN(dom.N, ccp.YNLT1); AddEvent2(dom.Y, EventsType.mouseover, Y_mouseover, EventsType.mouseleave, Y_mouseleave); AddEvent2(dom.N, EventsType.mouseover, N_mouseover, EventsType.mouseleave, N_mouseleave); }; var setvaried_div = function () { if (ccp.imgW > ccp.imgH) { ccp.varied_divWH = ccp.imgH < cfg.varied_divDEFAULT ? ccp.imgH : cfg.varied_divDEFAULT; } else { ccp.varied_divWH = ccp.imgW < cfg.varied_divDEFAULT ? ccp.imgW : cfg.varied_divDEFAULT; } ccp.varied_divL = Math.round((ccp.imgW - ccp.varied_divWH) / 2); ccp.varied_divT = Math.round((ccp.imgH - ccp.varied_divWH) / 2); ccp.varied_divMaxL = ccp.imgW - ccp.varied_divWH; ccp.varied_divMaxT = ccp.imgH - ccp.varied_divWH; setLTWH(dom.varied_div, ccp.varied_divL, ccp.varied_divT, ccp.varied_divWH, ccp.varied_divWH); }; var setvaried_div_img = function () { ccp.varied_div_imgL = -ccp.varied_divL; ccp.varied_div_imgT = -ccp.varied_divT; setLT(dom.varied_div_img, ccp.varied_div_imgL, ccp.varied_div_imgT); }; var setpreimg = function () { var p1, p2, p3; p1 = ccp.ctnaWH / ccp.varied_divWH; p2 = ccp.ctnbWH / ccp.varied_divWH; p3 = ccp.ctncWH / ccp.varied_divWH; ccp.imgaW = Math.round(p1 * ccp.imgW); ccp.imgaH = Math.round(p1 * ccp.imgH); ccp.imgaL = Math.round(p1 * ccp.varied_div_imgL); ccp.imgaT = Math.round(p1 * ccp.varied_div_imgT); ccp.imgbW = Math.round(p2 * ccp.imgW); ccp.imgbH = Math.round(p2 * ccp.imgH); ccp.imgbL = Math.round(p2 * ccp.varied_div_imgL); ccp.imgbT = Math.round(p2 * ccp.varied_div_imgT); ccp.imgcW = Math.round(p3 * ccp.imgW); ccp.imgcH = Math.round(p3 * ccp.imgH); ccp.imgcL = Math.round(p3 * ccp.varied_div_imgL); ccp.imgcT = Math.round(p3 * ccp.varied_div_imgT); setLTWH(dom.imga, ccp.imgaL, ccp.imgaT, ccp.imgaW, ccp.imgaH); setLTWH(dom.imgb, ccp.imgbL, ccp.imgbT, ccp.imgbW, ccp.imgbH); setLTWH(dom.imgc, ccp.imgcL, ccp.imgcT, ccp.imgcW, ccp.imgcH); }; var set_ccp = function () { ccp.ctnL = ccp.preW + 3 + Math.ceil((ccp.ccpW - ccp.imgW) / 2); ccp.ctnT = 1 + Math.ceil((ccp.ccpH - ccp.imgH) / 2); setLTWH(dom.ctn, ccp.ctnL, ccp.ctnT, ccp.imgW, ccp.imgH); ccp.black_coverL = ccp.preW + 3; ccp.black_coverT = 1; setLTWH(dom.black_cover, ccp.black_coverL, ccp.black_coverT, ccp.ccpW, ccp.ccpH); setLTWH(dom.fixed_img, 0, 0, ccp.imgW, ccp.imgH); dom.fixed_img.src = ccp.imgURL; setvaried_div(); setWH(dom.varied_div_img, ccp.imgW, ccp.imgH); dom.varied_div_img.src = ccp.imgURL; setvaried_div_img(); setpreimg(); }; var setStart = function () { set_pre(); set_bt(); set_ccp(); Show3(dom.pre, dom.ccp, dom.bt); }; var setImgWH = function (src, type) { var image = new Image(); image.onload = function () { var width = this.width, height = this.height;//图片的宽高 var p = width / height; if (p > 1) { if (p > ccp.ccpW / 50) { alert("图片宽高比不能超过" + p); return; } else { if (height < 50) { ccp.imgN = height / 50; ccp.imgH = 50; ccp.imgW = Math.round(ccp.imgH * p); } else if (width > ccp.ccpW) { ccp.imgN = width / ccp.ccpW; ccp.imgW = ccp.ccpW; ccp.imgH = Math.round(ccp.imgW / p); } else { ccp.imgN = 1; ccp.imgW = width; ccp.imgH = height; } } } else { if (p < 50 / ccp.ccpH) { alert("图片宽高比不能小于" + p); return; } else { if (width < 50) { ccp.imgN = width / 50; ccp.imgW = 50; ccp.imgH = Math.round(ccp.imgW / p); } else if (height > ccp.ccpH) { ccp.imgN = height / ccp.ccpH; ccp.imgH = ccp.ccpH; ccp.imgW = Math.round(ccp.imgH * p); } else { ccp.imgN = 1; ccp.imgW = width; ccp.imgH = height; } } } ccp.imgURL = this.src; delete image; setStart(); }; image.onerror = function () { alert("图片已损坏,请上传正确图片"); }; image.src = src; }; var SelectPicture_click = function () { dom.upfile = document.createElement("input"); setAttr2(dom.upfile, "type", "file", "id", "upfile"); dom.upfile.click(); dom.upfile.onchange = function () { ccp.file = this.files[0]; ccp.imgtype = ccp.file.type; if (!check_imgtype()) { return; } //检查文件类型 ccp.imgsize = ccp.file.size; if (!check_imgsize()) { return; }; //检查图片大小 var reader = new FileReader(); reader.onload = function () { setImgWH(this.result, ccp.imgtype); }; reader.readAsDataURL(ccp.file); }; };
ccp.css
*{ margin:0px; padding:0px; } #SelectPicture{ position:absolute; border:3px solid #ff6a00; border-radius:8px; color:#ff6a00; text-align:center; font-family:'Microsoft YaHei'; cursor:pointer; } #upfile{ display:none; } #pre,#ccp,#bt{ float:left; z-index:1; border:1px solid #ffffff; } #ccp{ border:1px dashed #808080; border-left:1px dashed #808080; border-right:1px dashed #808080; } #prea,#preb,#prec{ position:absolute; background-color:#ff6a00; border-radius:7px; } #ctna,#ctnb,#ctnc{ position:absolute; background-color:#ffffff; overflow:hidden; } #imga,#imgb,#imgc{ position:absolute; left:0px; top:0px; } #Y_OUT,#N_OUT{ position:absolute; } #Y,#N{ /* background-color:#ff6a00;*/ position:absolute; text-align:center; border:3px solid #ff6a00; border-radius:50%; color:#ff6a00; font-family:Arial; cursor:pointer; } #ctn{ position:absolute; background-color:blueviolet; overflow:hidden; } #black_cover{ position:absolute; background-color:black; opacity:0.6; z-index:3; } #fixed_img{ position:absolute; } #varied_div{ position:absolute; z-index:4; overflow: hidden; cursor:move; } #BottomRight,#TopRight,#TopLeft,#BottomLeft { background:#D6FB66; display:block; width:6px; height:6px; position:absolute; z-index:5; bottom:0; right:0; cursor:nw-resize; } #BottomLeft { bottom:0; left:0; cursor:ne-resize; } #TopRight { top:0; right:0; cursor:ne-resize; } #TopLeft { top:0; left:0; cursor:nw-resize; } #varied_div_img{ position:absolute; z-index:5; }
The above is the entire content of this article. I hope it will be helpful to everyone in learning javascript programming.

The shift from C/C to JavaScript requires adapting to dynamic typing, garbage collection and asynchronous programming. 1) C/C is a statically typed language that requires manual memory management, while JavaScript is dynamically typed and garbage collection is automatically processed. 2) C/C needs to be compiled into machine code, while JavaScript is an interpreted language. 3) JavaScript introduces concepts such as closures, prototype chains and Promise, which enhances flexibility and asynchronous programming capabilities.

Different JavaScript engines have different effects when parsing and executing JavaScript code, because the implementation principles and optimization strategies of each engine differ. 1. Lexical analysis: convert source code into lexical unit. 2. Grammar analysis: Generate an abstract syntax tree. 3. Optimization and compilation: Generate machine code through the JIT compiler. 4. Execute: Run the machine code. V8 engine optimizes through instant compilation and hidden class, SpiderMonkey uses a type inference system, resulting in different performance performance on the same code.

JavaScript's applications in the real world include server-side programming, mobile application development and Internet of Things control: 1. Server-side programming is realized through Node.js, suitable for high concurrent request processing. 2. Mobile application development is carried out through ReactNative and supports cross-platform deployment. 3. Used for IoT device control through Johnny-Five library, suitable for hardware interaction.

I built a functional multi-tenant SaaS application (an EdTech app) with your everyday tech tool and you can do the same. First, what’s a multi-tenant SaaS application? Multi-tenant SaaS applications let you serve multiple customers from a sing

This article demonstrates frontend integration with a backend secured by Permit, building a functional EdTech SaaS application using Next.js. The frontend fetches user permissions to control UI visibility and ensures API requests adhere to role-base

JavaScript is the core language of modern web development and is widely used for its diversity and flexibility. 1) Front-end development: build dynamic web pages and single-page applications through DOM operations and modern frameworks (such as React, Vue.js, Angular). 2) Server-side development: Node.js uses a non-blocking I/O model to handle high concurrency and real-time applications. 3) Mobile and desktop application development: cross-platform development is realized through ReactNative and Electron to improve development efficiency.

The latest trends in JavaScript include the rise of TypeScript, the popularity of modern frameworks and libraries, and the application of WebAssembly. Future prospects cover more powerful type systems, the development of server-side JavaScript, the expansion of artificial intelligence and machine learning, and the potential of IoT and edge computing.

JavaScript is the cornerstone of modern web development, and its main functions include event-driven programming, dynamic content generation and asynchronous programming. 1) Event-driven programming allows web pages to change dynamically according to user operations. 2) Dynamic content generation allows page content to be adjusted according to conditions. 3) Asynchronous programming ensures that the user interface is not blocked. JavaScript is widely used in web interaction, single-page application and server-side development, greatly improving the flexibility of user experience and cross-platform development.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

WebStorm Mac version
Useful JavaScript development tools

Dreamweaver CS6
Visual web development tools