• 图片裁剪


    function img_adaption(img) {
        if (!$(img).hasClass('img_adapted')) {
            $(img).css({'display''none'});
            var originalWidth = $(img).width();
            var originalHeight = $(img).height();
            var parentWidth = $(img).parent().width();
            var parentHeight = $(img).parent().height();
            var originalScale = originalWidth / originalHeight;
            var parentScal = parentWidth / parentHeight;
            var scaleNum, newImgWidth;
            var newImgHeight = 0;
            var changeNum = 0;
            if ($(img).parent().css('position') == 'static') {
                $(img).parent().css({
                    'position''relative',
                    'overflow''hidden'
                })
            }
            if (originalScale > parentScal) {
                scaleNum = originalHeight / parentHeight;
                newImgWidth = originalWidth / scaleNum;
                changeNum = (newImgWidth - parentWidth) / 2;
                $(img).css({
                    'width''auto',
                    'height': parentHeight,
                    'margin-left': -changeNum,
                    'display''block',
                    'border-radius''0'
                });
                $(img).fadeIn();
            else if (originalScale < parentScal) {
                scaleNum = originalWidth / parentWidth;
                newImgHeight = originalHeight / scaleNum;
                changeNum = (newImgHeight - parentHeight) / 2;
                $(img).css({
                    'width': parentWidth,
                    'height''auto',
                    'margin-top': -changeNum,
                    'display''block',
                    'border-radius''0'
                });
                $(img).fadeIn();
            else {
                $(img).css({
                    'width''100%',
                    'height''100%',
                    'display''block'
                });
                $(img).fadeIn();
            }
     
            $(img).addClass('img_adapted');
        else {
            $(img).css({'display''block'})
        }
    }
  • 相关阅读:
    PHPExcel读取excel03/07版到数组
    firefox 自定义快捷键
    phpstorm 自定义函数配置
    解决FPDF报错:FPDF error: Not a JPEG file / FPDF error: Not a PNG file
    mysql学习笔记
    定时备份服务器数据库(借助windows任务计划以及mysqldump)
    discuz 注册用户用到的几个表
    phpstorm配置取消掉63342
    discuz random函数
    discuz X3.2邮箱非必填
  • 原文地址:https://www.cnblogs.com/cy1121/p/9555019.html
Copyright © 2020-2023  润新知