zoukankan      html  css  js  c++  java
  • 头像“截取”,图片使用居中显示,在头像跟上传中应该用的到

    喜欢的朋友可以自己去下载一下。 https://pan.baidu.com/s/1eS1B50e 点击下载

    PS:无论图片怎么样,外面设置一个div,图片能始终以图片自身的中心位置开始显示在div中间  对于做头像很有用,喜欢的朋友可以看看,菜鸟一个,不好的地方请留言指出

     HTML中

    <div class="pictures">
    <img src="18.jpg" alt=""/>
    </div>

    <div class="pictures">
    <img src="5.jpg" alt=""/>
    </div>
    <div class="pictures">
    <img src="13.jpg" alt=""/>
    </div>
    <div class="pictures">
    <img src="24.jpg" alt=""/>
    </div>
    <script src="jquery1.9.0.js"></script>
    <script src="demo.js"></script>


    引入了JQ的框架 所以在使用的时候需要引入JQ(1.9以上)
    demo.js文件中代码如下:
    function middleP(className, width, height) {
    $("." + className).css({
    "width": width,
    "height": height,
    "overflow": "hidden",
    "position": "relative"
    })
    var imgArr = $("." + className).find("img");
    var x,y;
    for (var i = 0; i < imgArr.length; i++) {
    imgSize($(imgArr[i]), width, height);
    //imgMargin($(imgArr[i]),width,height);
    (function (imgArr,width,height) {
    x = ( imgArr.width() - width) / 2;
    y = ( imgArr.height() - height) / 2;
    $(imgArr.css({
    "margin-left": -x,
    "margin-top": -y
    }))
    })($(imgArr[i]),width,height);

    }
    };
    function imgSize(img, width, height) {
    if (img.width() >= img.height()) {
    if(height>=width){
    img.css({
    "height": height,
    "width": "auto"
    })
    }else{
    img.css({
    "height": "auto",
    "width":width
    })
    }

    } else {
    if(height>=width){
    img.css({
    "height": "auto",
    "width": width
    })
    }else{
    img.css({
    "width": "auto",
    "height": height
    })
    }


    }
    }

    $(window).load(function(){
    middleP("pictures",100,100);//参数1:类名 参数2:显示的宽度 参数3:显示的高度
    })
  • 相关阅读:
    codeforces689A
    codeforces222A
    codeforces553A
    2021牛客国庆集训派对day6 J
    SVM--支持向量机
    压缩感知
    范数
    LeNet详解
    卷积神经网络(CNN)详解
    BP算法实例—鸢尾花的分类(Python)
  • 原文地址:https://www.cnblogs.com/leolovexx/p/5819345.html
Copyright © 2011-2022 走看看