Web前端,用JS实现:根据浏览器宽度,用缩放的方式,自动调整网页大小。
JS代码如下:
function adjustZoom() {
var reZoom = false;
var zoom = get_cookie("zoom");
if(zoom == undefined ){
reZoom = true;
}
if(isNaN(zoom) == true){
reZoom = true;
}
if(zoom != undefined && isNaN(zoom) == false){
if(zoom == 1){
reZoom = true;
}
if(zoom == 0){
reZoom = true;
}
}
if(reZoom == true){
if(window.innerWidth > 1024){
document.body.style.zoom = window.innerWidth / 1584;
}else{
document.body.style.zoom = 1;
}
}
}
// 初始调整
adjustZoom();
// 窗口大小改变时重新调整
window.addEventListener('resize', adjustZoom);
如果不进行自动窗口调整,在大分辨率情况下,浏览器窗口过大时,页面会不那么美观。
如果不想他人知道自己是如何实现这个功能的,可以将JS代码加密,比如用JShaman、JS-Obfuscator等提供的JS代码混淆加密服务:
JS加密结果,如下:
var _0x5g7dec = ["|", "zoom", "resize"];
function _0xa505e() {
var _0xa = '\u0036\u007c\u0033\u007c\u0038\u007c\u0031\u007c\u0037\u007c\u0032\u007c\u0039\u007c\u0030\u007c\u0035\u007c\u0034'['\x73\x70\x6c\x69\x74'](_0x5g7dec[0]),
_0xa766fa = function (s, h) {
return eval(String.fromCharCode(115, 32, 94, 32, 104));
}(157565, 157565);
while (!![]) {
switch (+_0xa[eval(String.fromCharCode(95, 48, 120, 97, 55, 54, 54, 102, 97, 43, 43))]) {
case eval(String.fromCharCode(52, 52, 51, 54, 51, 56, 32, 94, 32, 52, 52, 51, 54, 51, 56)):
if (eval(String.fromCharCode(105, 115, 78, 97, 78, 40, 95, 48, 120, 97, 56, 100, 98, 49, 98, 41, 32, 61, 61, 32, 33, 33, 91, 93))) {
_0x6e5bab = function () {
return !![];
}();
}
continue;
case eval(String.fromCharCode(50, 56, 57, 52, 52, 50, 32, 94, 32, 50, 56, 57, 52, 52, 51)):
var _0x78953b = function (s, h) {
return eval(String.fromCharCode(115, 32, 43, 32, 104));
}(eval(String.fromCharCode(50, 56, 56, 54, 50, 50, 32, 94, 32, 50, 56, 56, 54, 49, 55)), eval(String.fromCharCode(50, 48, 56, 54, 48, 48, 32, 94, 32, 50, 48, 56, 54, 48, 52)));
continue;
case eval(String.fromCharCode(55, 49, 49, 54, 57, 56, 32, 94, 32, 55, 49, 49, 54, 57, 54)):
_0x78953b = function () {
return eval(String.fromCharCode(49, 57, 50, 48, 54, 52, 32, 94, 32, 49, 57, 50, 48, 55, 48));
}();
continue;
case 199998 ^ 199997:
var _0x6e5bab = ![];
continue;
case eval(String.fromCharCode(53, 50, 54, 52, 50, 50, 32, 94, 32, 53, 50, 54, 52, 49, 56)):
if (eval(String.fromCharCode(95, 48, 120, 54, 101, 53, 98, 97, 98, 32, 61, 61, 32, 33, 33, 91, 93))) {
if (eval(String.fromCharCode(119, 105, 110, 100, 111, 119, 91, 39, 92, 120, 54, 57, 92, 120, 54, 101, 92, 120, 54, 101, 92, 120, 54, 53, 92, 120, 55, 50, 92, 120, 53, 55, 92, 120, 54, 57, 92, 120, 54, 52, 92, 120, 55, 52, 92, 120, 54, 56, 39, 93, 32, 62, 32, 40, 50, 53, 56, 54, 50, 55, 32, 94, 32, 50, 53, 57, 54, 53, 49, 41))) {
document['\x62\x6f\x64\x79']['\x73\x74\x79\x6c\x65']['\x7a\x6f\x6f\x6d'] = eval(String.fromCharCode(119, 105, 110, 100, 111, 119, 91, 39, 92, 120, 54, 57, 92, 120, 54, 101, 92, 120, 54, 101, 92, 120, 54, 53, 92, 120, 55, 50, 92, 120, 53, 55, 92, 120, 54, 57, 92, 120, 54, 52, 92, 120, 55, 52, 92, 120, 54, 56, 39, 93, 32, 47, 32, 40, 57, 52, 54, 49, 48, 53, 32, 94, 32, 57, 52, 52, 53, 50, 49, 41));
} else {
document['\x62\x6f\x64\x79']['\x73\x74\x79\x6c\x65']['\x7a\x6f\x6f\x6d'] = function () {
return 752668 ^ 752669;
}();
}
}
continue;
case eval(String.fromCharCode(56, 57, 50, 50, 56, 56, 32, 94, 32, 56, 57, 50, 50, 57, 51)):
if (_0xa8db1b != undefined && isNaN(_0xa8db1b) == ![]) {
if (eval(String.fromCharCode(95, 48, 120, 97, 56, 100, 98, 49, 98, 32, 61, 61, 32, 40, 53, 48, 50, 53, 51, 57, 32, 94, 32, 53, 48, 50, 53, 51, 56, 41))) {
_0x6e5bab = function () {
return !![];
}();
}
if (eval(String.fromCharCode(95, 48, 120, 97, 56, 100, 98, 49, 98, 32, 61, 61, 32, 40, 55, 54, 57, 54, 54, 56, 32, 94, 32, 55, 54, 57, 54, 54, 56, 41))) {
_0x6e5bab = function () {
return !![];
}();
}
}
continue;
case 360889 ^ 360895:
var _0xfec26d;
continue;
case eval(String.fromCharCode(50, 51, 56, 49, 56, 57, 32, 94, 32, 50, 51, 56, 49, 56, 54)):
var _0xa8db1b = get_cookie(_0x5g7dec[1]);
continue;
case 220662 ^ 220670:
_0xfec26d = eval(String.fromCharCode(40, 53, 53, 54, 52, 53, 50, 32, 94, 32, 53, 53, 54, 52, 54, 49, 41, 32, 43, 32, 40, 50, 51, 56, 52, 57, 48, 32, 94, 32, 50, 51, 56, 52, 57, 48, 41));
continue;
case 151379 ^ 151386:
if (eval(String.fromCharCode(95, 48, 120, 97, 56, 100, 98, 49, 98, 32, 61, 61, 32, 117, 110, 100, 101, 102, 105, 110, 101, 100))) {
_0x6e5bab = function () {
return !![];
}();
}
continue;
}
break;
}
}
_0xa505e();
window['\x61\x64\x64\x45\x76\x65\x6e\x74\x4c\x69\x73\x74\x65\x6e\x65\x72'](_0x5g7dec[2], _0xa505e);
本文最初提供的代码,经加密后,可成为以上混乱形式,他人就不能轻易知道代码逻辑了。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。