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;

  • 相关阅读:
    HDU4608+模拟
    七、cocos2dx之粒子系统
    组织机构代码校验码 验证程序
    公民身份号码 校验码 检证程序
    百度地图之短串分享
    HDU 1421 DP
    动物:黄鼬、黄鼠狼
    动物-昆虫-蜂:马蜂
    动物-昆虫-蜂:青米蜂
    动物-昆虫-蜂:土蜂
  • 原文地址:https://www.cnblogs.com/wwyydd/p/14356091.html
Copyright © 2011-2022 走看看