注冊|登錄

聯系電話:024-31891684  13390130939
沈陽軟件公司--沈陽軟件定制

沈陽軟件開發_沈陽軟件公司_沈陽軟件定制/軟件/最新技術

Latest technology最新技術

JS控制圖片翻轉代碼,兼容firefox,ie,chrome等瀏覽器

瀏覽量:4602

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<title>圖片旋轉效果</title>

<meta http-equiv="content-type" content="text/html;charset=gb2312">

<!--把下面代碼加到<head>與</head>之間-->

<style type="text/css">

ul{padding:0 15px;}

ul li{padding-bottom:15px;border-bottom:1px dashed #EEE;}

.caption{padding:15px 0 5px;}

.caption input{margin-right:10px;padding:0 10px;}

</style>

<script type="text/javascript">

/*

* www.byzuo.com

* ok!: MSIE 6, 7, 8, Firefox 3.6, chrome 4, Safari 4, Opera 10

* o 旋轉圖片ID;

* p 選擇旋轉方向,固定值為'left'或'right';

*/

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);

//MSIE

if(document.all) {

img.style.filter = 'progid:DXImageTransform.Microsoft.BasicImage(rotation='+ n +')';

//HACK FOR MSIE 8

switch(n){

case 0:

imgimg.parentNode.style.height = img.height;

break;

case 1:

imgimg.parentNode.style.height = img.width;

break;

case 2:

imgimg.parentNode.style.height = img.height;

break;

case 3:

imgimg.parentNode.style.height = img.width;

break;

}

//DOM

}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 ccanvasContext = 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;

}

}

}

</script>

</head>

<body>

<!--把下面代碼加到<body>與</body>之間-->

<ul class="clearfix">

<li>

<div class="caption">

<input type="button" value="turn left" onclick="rotate('pic_1','left')">

<input type="button" value="turn right" onclick="rotate('pic_1','right')">

</div>

<div class="cont">

<img alt="javascript 圖片旋轉效果" id="pic_1" src="1.gif" alt="">

</div>

</li>

</ul>

</body>

</html>

上一篇:js級聯

下一篇:淺談并發

沈陽團購網|營口網站制作|沈陽軟件公司|軟件定制|網站建設|加盟易勢|提交問題

主站蜘蛛池模板: 17女生主动让男生桶自己比| 久久国产亚洲电影天堂| 精品久久久久久久久中文字幕| 国产性猛交╳XXX乱大交| 91se在线视频| 天天欲色成人综合网站| 中文字幕不卡在线| 日韩一区二区三区无码影院| 亚洲人成精品久久久久| 毛片免费vip会员在线看| 免费福利在线播放| 老司机福利深夜亚洲入口| 国产女人乱人伦精品一区二区| 视频免费在线观看| 在线中文字幕观看| igao视频在线| 强开小婷嫩苞又嫩又紧视频| 久久99精品久久久久久水蜜桃| 日韩在线视频免费播放| 亚洲va久久久噜噜噜久久| 欧美成成人免费| 亚洲精品无码专区在线| 男女裸体影院高潮| 动漫美女被免费漫画| 老司机福利精品视频| 国产乡下三级全黄三级| 高潮毛片无遮挡高清免费视频 | 亚洲av无码片vr一区二区三区| 欧美综合人人做人人爱| 亚洲色中文字幕在线播放| 秋霞理论最新三级理论最| 古代级a毛片在线| 色伊人国产高清在线| 国产亚洲一区二区手机在线观看 | 91在线精品中文字幕| 天天射天天操天天色| 一女多男在疯狂伦交在线观看| 成人影院wwwwwwwwwww| 中文字幕视频在线观看| 日本在线小视频| 久久天天躁狠狠躁夜夜|