• js 旋转图片


    /*图片转动函数*/
    function rotate(o, p) {
    var img = document.getElementById(o);
    if(!img || !p) return false;
    var n = img.getAttribute('step');
    if(n == null) n=0;
    if(p=='right') {
    (n==3)?n=0:n++;
    }
    else if(p="left"){
    (n==0)?n=3:n--;
    }
    img.setAttribute('step', n);

    if(document.all) {
    img.style.filter = "progid:DXImageTransform.Microsoft.BasicImage(rotation="+ n +")";

    switch(n){
    case 0:
    img.parentNode.style.height = img.height;
    break;
    case 1:
    img.parentNode.style.height = img.width;
    break;
    case 2:
    img.parentNode.style.height = img.height;
    break;
    case 3:
    img.parentNode.style.height = img.width;
    break;
    }
    }
    else{
    var c = document.getElementById('canvas_'+o);
    if(c==null){
    img.style.visibility = 'hidden';
    img.style.position = 'absolute';
    c = document.createElement('canvas');
    c.setAttribute('id', 'canvas_'+o);
    img.parentNode.appendChild(c);
    }
    var canvasContext = c.getContext('2d');
    canvasContext.save();
    switch(n){
    default :
    case 0:
    c.setAttribute('width', img.width);
    c.setAttribute('height', img.height);
    canvasContext.rotate(0 * Math.PI/180);
    canvasContext.drawImage(img, 0, 0);
    break;
    case 1:
    c.setAttribute('width', img.height);
    c.setAttribute('height', img.width);
    canvasContext.rotate(90 * Math.PI/180);
    canvasContext.drawImage(img, 0, -img.height);

    break;
    case 2:
    c.setAttribute('width', img.width);
    c.setAttribute('height', img.height);
    canvasContext.rotate(180 * Math.PI/180);
    canvasContext.drawImage(img, -img.width, -img.height);
    break;
    case 3:
    c.setAttribute('width', img.height);
    c.setAttribute('height', img.width);
    canvasContext.rotate(270 * Math.PI/180);
    canvasContext.drawImage(img, -img.width, 0);
    break;

    }
    canvasContext.restore();
    }

    }

  • 相关阅读:
    AcWing 1081. 度的数量
    CF584D Dima and Lisa
    [ABC130F] Minimum Bounding Box
    AT4289 [ABC133E] Virus Tree 2
    Arc of Dream HDU
    Reading comprehension HDU
    【洛谷 1541】乌龟棋
    【洛谷 4880】抓住czx
    【洛谷 1525】关押罪犯
    【洛谷 1040】加分二叉树
  • 原文地址:https://www.cnblogs.com/liubingna/p/2919308.html
Copyright © 2020-2023  润新知