JS 实现兼容IE图片向左或向右翻转
<!DOCTYPE HTML>
<head>
<title>JS实现图片向左向右翻转</title>
<meta http-equiv="content-type" content="text/html;charset=UTF-8">
<script type="text/javascript">
function rotate(o, p) {
var img = document.geiElmentById(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 +')';
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 canvasContent = c.getContext('2d');
switch(n) {
default:
case 0:
c.setAttribute('width', img.width);
c.setAttribute('height', img.height);
canvasContent.rotate(0 * Math.PI / 180);
canvasContent.drawImage(img, 0, 0);
break;
case 1:
c.setAttribute('width', img.width);
c.setAttribute('height', img.height);
canvasContent.rotate(90 * Math.PI / 180);
canvasContent.drawImage(img, 0, -img.height);
break;
case 2:
c.setAttribute('width', img.width);
c.setAttribute('height', img.height);
canvasContent.rotate(180 * Math.PI / 180);
canvasContent.drawImage(img, -img.width, -img.height);
break;
case 3:
c.setAttribute('width', img.width);
c.setAttribute('height', img.height);
canvasContent.rotate(270 * Math.PI / 180);
canvasContent.drawImage(img, -img.width, 0);
break;
}
}
}
</script>
</head>
<body>
<div class="container">
<input type="button" value="turn left" onclick="rotate('pic', 'left')" />
<input type="button" value="turn right" onclick="rotate('pic', 'right')" />
<div class="cont" onclick="rotate('pic', 'right')">
<img id="pic" src="1.jpg" alt="" />
</div>
</div>
</body>
</html>
JS 实现兼容IE图片向左或向右翻转的更多相关文章
- vue+hammer.js完美实现长按、左滑,右滑等触控事件
移动端使用手指直接操作的方式大受用户欢迎,这其中就包括了单点.多点.长按.双击等方式. 这么多触控事件,如果开发者自己实现,会浪费大量的时间和精力,快来看看 hammer.js 让我们轻松了多少吧. ...
- 图片旋转+剪裁js插件(兼容各浏览器) « 张鑫旭-鑫空间-鑫生活
图片旋转+剪裁js插件(兼容各浏览器) « 张鑫旭-鑫空间-鑫生活 图片旋转+剪裁js插件(兼容各浏览器) by zhangxinxu from http://www.zhangxinxu.com 本 ...
- 关于js的兼容问题(小办法)!
今天整理了一下浏览器对JS的兼容问题,希望能给你们带来帮助,我没想到的地方请留言给我,我再加上: 常遇到的关于浏览器的宽高问题: //以下均可console.log()实验 var winW=docu ...
- 原生js和jquery实现图片轮播特效
本文给大家分享的是使用原生JS和JQ两种方法分别实现相同的图片轮播特效,十分的实用,也非常方便大家对比学习原生js和jQuery,有需要的小伙伴可以参考下. 1)首先是页面的结构部分对于我这种左右切换 ...
- 原生js和jquery实现图片轮播特效(转)
本文给大家分享的是使用原生JS和JQ两种方法分别实现相同的图片轮播特效,十分的实用,也非常方便大家对比学习原生js和jQuery,有需要的小伙伴可以参考下. 1)首先是页面的结构部分对于我这种左右切换 ...
- 前端js保存页面为图片下载到本地
前端js保存页面为图片下载到本地 手机端点击下载按钮将页面保存成图片到本地 前端js保存页面为图片下载到本地的坑 html2canvas 识别 svg 解决方案 方案 html2canvas.js:可 ...
- js鼠标滚轮滚动图片切换效果
效果体验网址:http://keleyi.com/keleyi/phtml/image/12.htm HTML文件代码: <!DOCTYPE html PUBLIC "-//W3C// ...
- js控制 固定框架内图片 按比例显示 以及 占满框架 居中显示
js控制 固定框架内图片 等比例显示 以及 占满框架 纵横居中显示 通过设置 js函数 fitDiv里面var fit的值就好 function fitDiv (obj) { var target_w ...
- 设为首页 和 收藏本站js代码 兼容IE,chrome,ff
设为首页 和 收藏本站js代码 兼容IE,chrome,ff //设为首页 function SetHome(obj,url){ try{ obj.style.behavior='url(#defau ...
随机推荐
- VS2013 Winform程序打包部署 InstallShield2015LimitedEdition
VS2013 Winform程序打包部署 VS2013默认是没有安装打包程序的,需要手动安装,我安装的是 InstallShield2015LimitedEdition. 1.点击解决方案,右键,选择 ...
- es6中的双箭头函数
原代码: const fetchPosts = subreddit => dispatch => { dispatch(requestPosts(subreddit)); return c ...
- initWithFrame方法的使用
1. initWithFrame方法是什么? initWithFrame方法用来初始化并返回一个新的视图对象,根据指定的CGRect(尺寸). 当然,其他UI对象,也有initWithFrame方法, ...
- 导入到eclipse里的工程挺大的,然后就一直报: An internal error occurred during: "Building workspace". GC overhead limit exceeded 这个错误。
解决方法: 原因是Eclipse默认配置内存太小需要更改Eclipse安装文件夹下的eclipse.ini文件. Eclipse.ini默认文件如下: 修改如下: -Xms1024m -Xmx2048 ...
- hdu 1372 BFS
A friend of you is doing research on the Traveling Knight Problem (TKP) where you are to find the sh ...
- Java中HBase的集中過濾器
比較過濾器: rowKey过滤器 RowFilter 列族过滤器 FamilyFilter 列过滤器 QualifierFilter 列值过滤器 ...
- 谈一谈java中的Canves机制
0--写在前面: 很多初学java的童鞋,常常很苦恼,一天天的都跟命令行较劲,好像很无聊的样子,如果能跳出命令行做出界面甚至一个画图界面,那将是一件很兴奋的事情:也可以让编程变的有趣:有脑洞的同学还可 ...
- Python 找零问题
#coding = utf-8 def Change_Money(money): print('总金额:'+str(money)+'元') loop=True tmp=[] # 面值列表 单位:元 t ...
- Python实例之抓取HTML中的数据并保存为TXT
本实例实现了抓取捧腹网中存储于html中的笑话数据(非JSON数据) 通过浏览器相关工具发现捧腹网笑话页面的数据存储在HTML页面而非json数据中,因此可以直接使用soup.select()方法来抓 ...
- 常识判断-科技-day123
PS: 在常识中科技是最难的 PS: 20-2w HZ是人能听到的频率 PS: 物体的熔点和凝固点是一致的 PS: 氮肥如果多了,可能只是长叶子不结果: 磷肥促进开花结果 PS; 病毒是介于生物和非 ...