手机端 图片的移动缩放旋转兼容touch
//缩放
var initialScale = 1;
var currentScale = 1;
touch.on('#target', 'pinch', function (ev) {
currentScale = ev.scale - 1;
currentScale = initialScale + currentScale;
currentScale = currentScale > 1.5 ? 1.5 : currentScale;
currentScale = currentScale < 0.5 ? 0.5 : currentScale;
this.style.webkitTransform = 'scale(' + currentScale + ')' + ' ' + 'rotate(' + totalAngle + 'deg)';
this.style.webkitTransition = 'all ease 0.05s';
});
//旋转
var angle = 0;
var totalAngle = 0;
touch.on('#target', 'rotate', function (ev) {
totalAngle = angle + ev.rotation;
if (ev.fingerStatus === 'end') {
angle = angle + ev.rotation;
}
this.style.webkitTransform = 'rotate(' + totalAngle + 'deg)' + ' ' + 'scale(' + currentScale + ')';
});
//拖拽,第二个为true是背景图拖拽
var fBindDrag = function (obj, outmove) {
var obj = $(obj);
var pt = obj.parent();
var xy = null; obj.xy();
touch.on(obj[0], 'touchstart', function (ev) {
if (true) { xy = { x: obj[0].offsetLeft, y: obj[0].offsetTop } }
// ev.preventDefault();
});
var dx, dy;
touch.on(obj[0], 'drag', function (ev) {
dx = dx || 0;
dy = dy || 0;
var offx = dx + ev.x;
var offy = dy + ev.y;
var nx = xy.x + offx, ny = xy.y + offy;
if (outmove) {
if (nx > 0) {
nx = 0;
}
if (nx + obj[0].offsetWidth < pt[0].clientWidth) {
nx = pt[0].clientWidth - obj[0].offsetWidth;
}
if (ny > 0) { ny = 0; }
if (ny + obj[0].offsetHeight < pt[0].clientHeight) {
ny = pt[0].clientHeight - obj[0].offsetHeight;
}
} else {
if (nx < 0) {
nx = 0;
}
if (nx + obj[0].offsetWidth > pt[0].clientWidth) {
nx = pt[0].clientWidth - obj[0].offsetWidth;
}
if (ny < 0) { ny = 0; }
if (ny + obj[0].offsetHeight > pt[0].clientHeight) {
ny = pt[0].clientHeight - obj[0].offsetHeight+32;
}
}
obj.css("left", nx + "px");
obj.css("top", ny + "px");
});
touch.on(obj[0], 'dragend', function (ev) {
// dx += ev.x;
// dy += ev.y;
});
}
//背景图缩放,uploadImg为背景框
var fScale = function (obj) {
var obj = $(obj);
var target = obj[0];
var pt = obj.parent();
//target.style.webkitTransition = 'all ease 0.05s';
var ox, oy, ow, oh;
touch.on($("#uploadImg")[0], 'touchstart', function (ev) {
ox = target.offsetLeft;
oy = target.offsetTop;
ow = target.clientWidth;
oh = target.clientHeight;
// ev.preventDefault();
});
var initialScale = 1;
var currentScale;
touch.on($("#uploadImg")[0], 'pinch', function (ev) {
currentScale = ev.scale - 1;
var mw = target.clientWidth;
var mh = target.clientHeight;
var xywh = { x: 0, y: 0, w: 0, h: 0 };
xywh.w = ow * ev.scale;
if (xywh.w < pt[0].clientWidth) {
xywh.w = pt[0].clientWidth;
}
xywh.h = xywh.w * mh * 1.0 / mw;
if (xywh < pt[0].clientHeight) {
xywh.h = pt[0].clientHeight;
xywh.w = xywh.h * mw / mh;
}
xywh.x = ox - (xywh.w - ow) / 2;
xywh.y = oy - (xywh.h - oh) / 2;
if (xywh.x > 0) { xywh.x = 0; }
if (xywh.y > 0) { xywh.y = 0; }
if (xywh.x + target.offsetWidth < pt[0].clientWidth) {
xywh.x = 0;
}
if (xywh.y + target.offsetHeight < pt[0].clientHeight) {
xywh.y = 0;
}
index = 0;
obj.css({ left: xywh.x + 'px', top: xywh.y + 'px', width: xywh.w + 'px' });
});
touch.on($("#uploadImg")[0], 'pinchend', function (ev) {
});
}
手机端 图片的移动缩放旋转兼容touch的更多相关文章
- 手机端图片插件可缩放 旋转 全屏查看photoswipe
官方介绍PhotoSwipe 是专为移动触摸设备设计的相册/画廊.兼容所有iPhone.iPad.黑莓6+,以及桌面浏览器.底层实现基于HTML/CSS/JavaScript,是一款免费开源的相册产品 ...
- 使用localResizeIMG3+WebAPI实现手机端图片上传
前言 惯例~惯例~昨天发表的使用OWIN作为WebAPI的宿主..嗯..有很多人问..是不是缺少了什么 - - 好吧,如果你要把OWIN寄宿在其他的地方...代码如下: namespace Conso ...
- 手机端图片预览和缩放js
转至:http://blog.sina.com.cn/s/blog_c342e3090102vcxu.html 1.手机端的图片选择和预览 <input type="file" ...
- megapix-image插件 使用Canvas压缩图片上传 解决手机端图片上传功能的问题
最近在弄微信端的公众号.订阅号的相关功能,发现原本网页上用的uploadify图片上传功能到手机端有的手机类型上就不能用了,比如iphone,至于为啥我想应该不用多说了吧(uploadify使用fla ...
- css——手机端图片正确显示
这两天遇到的问题汇总(一): 1.图片在app端显示有差异:如下 左边图片是:图片显示太大,以至于让整个页面都失真的效果:右边是调好样式之后的效果,知道增 ...
- js动态改变图片热区坐标,手机端图片热区自适应
<img id='banner1' src="images/banner.jpg" usemap="#banner" border="0&quo ...
- js手机端图片弹出方法
1 $("img").click(function(){ //获取窗口可视大小 var width=$(window).width(); var height=$(window). ...
- iphone手机端图片错位修正的js代码
<script type="text/javascript"> $(function(){ // 获取终端的相关信息 var Terminal = { // 辨别移动终 ...
- Html5 手机端网页不允许缩放
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <t ...
随机推荐
- Cornerstone 3.0.3 for mac 破解版
破解版本 直接安装即可 解压密码:xclient.info 下载地址: 链接: https://pan.baidu.com/s/1mhD64vY 密码: nwmc
- Java基础知识二次学习-- 第一章 java基础
基础知识有时候感觉时间长似乎有点生疏,正好这几天有时间有机会,就决定重新做一轮二次学习,挑重避轻 回过头来重新整理基础知识,能收获到之前不少遗漏的,所以这一次就称作查漏补缺吧!废话不多说,开始! 第一 ...
- QT修改UI和源码后,程序页面还是原来页面的解决方法
发生原因: 移植了一个Qt程序在修改完QT的cpp源码和UI界面布局等内容后,重启点击QT Creator左下角的运行(Ctrl+R)编译程序并启动后,程序界面及修改内容并没有改变. 解决方式: 找到 ...
- ArrayList源码解析(三)
1.isEmpty() 如果此列表中没有元素,则返回 true /** * Returns <tt>true</tt> if this list contains no el ...
- Maven学习(四)
eclipse创建Maven web项目 1.创建新项目 选择File -> New ->Project 选择New Project窗口中选择 Maven -> Maven Proj ...
- Asynchronous and Distributed Programming in R with the Future Package
Every now and again someone comes along and writes an R package that I consider to be a 'game change ...
- R语言 模糊c均值(FCM)算法程序(转)
FCM <- function(x, K, mybeta = 2, nstart = 1, iter_max = 100, eps = 1e-06) { ## FCM ## INPUTS ## ...
- js实现省市区三级联动
电商平台或者一些网站的个人信息部分,通常会有填写地址的功能.该功能一般分为二级联动(省.市)和三级联动(省.市.区),只需要JavaScript就可以实现. 这里介绍一种很简洁易用的方法.参考地址:h ...
- 查看c语言的函数运行时间的简单模板
/* clock():捕捉从程序开始运行到 clock() 被调用时所耗费的时间,时间单位 是clock tick, 即:"时钟打点". 常数CLK_TCK:机器时钟每秒所走的时钟 ...
- jquery中html、text、val回调函数
先扫盲: 摘自菜鸟教程:jQuery 方法:text().html() 以及 val()拥有回调函数. 回调函数有两个参数:被选元素列表中当前元素的下标,以及原始(旧的)值.然后以函数新值返回您希望使 ...