function rotate(obj,arr){
...
// 对现代浏览器写入HTML5的元素进行旋转: canvas
}else{
var c = document.getElementById('canvas_'+obj)
if(c== null){
img.style.visibility = 'hidden'
img.style.position = 'absolute'
c = document.createElement('canvas')
c.setAttribute("id",'canvas_'+obj)
img.parentNode.appendChild(c)
}
var canvasContext = c.getContext('2d')
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
}
}
}
代码中,创建canvas元素对象,并将图片赋予canvas对象,当变量n处于不同的状态(上下左右四个方向)时,使用canvas重新对图像进行绘制。
#main{position:relative
height:3600px
width:1440px
z-index:-1
background:url("background.jpg") no-repeat center rgb(0,0,0)
}
附注:rgba属于css3,IE的低版本不支持的
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)