zoukankan      html  css  js  c++  java
  • 图片裁剪

    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'})
        }
    }
  • 相关阅读:
    KMP算法
    cocos2d-x jsbinding 在线更新策略设计
    AS3动画效果公式,常用处理公式代码,基本运动公式,三角公式
    理解引导行为:路径跟踪
    适用于任何语言的编程策略
    Using中return对象
    js计算两个时间相差天数
    fastReport 绑定DataBand数据源后还是打印出一条数据
    无法处理文件 MainForm.resx,因为它位于 Internet 或受限区域中,或者文件上具有 Web 标记。要想处理这些文件,请删除 Web 标记
    附加数据库后登陆报错
  • 原文地址:https://www.cnblogs.com/cy1121/p/9555019.html
Copyright © 2011-2022 走看看