zoukankan      html  css  js  c++  java
  • Js Math对象 abs() 方法

    语法

    Math.abs(x) // 必需。必须是一个数值。

    示例

    输出:

    7.25
    7.25
    2.75

    在项目中使用的方法 上传图片

    Init: function(up, file) {
    let alertMsg = cbFilesAddedParam.alertMsg;
    plupload.addFileFilter("img_ratio", function(ratio, file, cb) {
    if (file.type.indexOf("image") == -1) return cb(false);
    var originFile = file.getNative();
    var reader = new FileReader();
    var image = new Image();
    reader.readAsDataURL(originFile);
    reader.onload = function(_file) {
    image.src = _file.target.result;
    image.onload = function() {
    var meta = {
    this.width,
    height: this.height,
    src: this.src
    };
    var compat = Math.abs((meta.width / meta.height) - ratio.ratio) < 0.01;
    cb(compat);
    compat || layer.alert(ratio.alertMsg);
    };
    };
    });
    }
    资源搜索网站大全 https://www.renrenfan.com.cn 广州VI设计公司https://www.houdianzi.com

    关键代码

    reader.onload = function(_file) {
    image.src = _file.target.result;
    image.onload = function() {
    var meta = {
    this.width,
    height: this.height,
    src: this.src
    };
    var compat = Math.abs((meta.width / meta.height) - ratio.ratio) < 0.01;
    cb(compat);
    compat || layer.alert(ratio.alertMsg);
    };
    };

    精确代码

    var compat = Math.abs((meta.width / meta.height) - ratio.ratio) < 0.01;

  • 相关阅读:
    hdoj 1872 稳定排序
    nyoj 60 谁获得了最高奖学金
    hdoj 2066 一个人的旅行
    nyoj 8 一种排序
    bzoj1798 1
    bzoj4031
    SPOJ-HIGH
    学习笔记::矩阵树定理
    学习笔记::树上莫队
    Strip
  • 原文地址:https://www.cnblogs.com/wwyydd/p/14356091.html
Copyright © 2011-2022 走看看