JQuery,JS图片操作(上一张,下一张,旋转,放大,缩小)
1、html代码:我是从数据库获取图片路径。
<div id="divprint" align="center">
@{DataTable dt = (DataTable)ViewBag.filedetail;}
@{
DataRow dr2 = dt.Rows[];
<input type="hidden" name="srcId" id="srcId" value="@dr2["ImgId"]" />
<img src="/upload/contract/@dr2["fileSrc"]" id="imgsrc" style="margin:0 auto;width:95%;height:95%">
} </div>
<div style="position:fixed;bottom:0;margin-left:180px"> <a id="before" class="easyui-linkbutton" style="width:80px">上一张</a>
<a id="next" class="easyui-linkbutton" style="width:80px">下一张</a>
<a id="big" class="easyui-linkbutton" style="width:80px" onclick="ImageSuofang(true)">放大</a>
<a id="small" class="easyui-linkbutton" style="width:80px" onclick="ImageSuofang(false)"> 缩小</a>
<a id="rotate" class="easyui-linkbutton" style="width:80px">旋转</a>
</div>
2、jquery,js代码(这里是每次点击旋转90度。放大缩小是因为没有做图片会随着窗口变化而变化)
<script type="text/javascript">
$(document).ready(function () {
var arraySrc = new Array;
var index = ;
@foreach (DataRow dr in ViewBag.filedetail.Rows)
{
<text>
arraySrc[index] = "@dr["ImgId"],@dr["fileSrc"]";
index++;
</text>
} //上一张
$("#before").click(function () {
var srcId = $("#srcId").val();
for (var i = ; i < arraySrc.length; i++) {
var src = "";
var no = ;
if (arraySrc[i].split(',')[] == srcId) {
if (i >= ) {
src = "/upload/contract/" + arraySrc[i - ].split(',')[];
no = i - ;
} else {
src = "/upload/contract/" + arraySrc[i].split(',')[];
no = i;
}
$("#imgsrc").attr('src', src);
$("#srcId").val(no);
}
}
})
//下一张
$("#next").click(function () {
var srcId = $("#srcId").val();
for (var i = ; i < arraySrc.length; i++) {
var src = "";
var no = ;
if (arraySrc[i].split(',')[] == srcId) {
if (i <= arraySrc.length - ) {
src = "/upload/contract/" + arraySrc[i + ].split(',')[];
no = i + ;
} else {
src = "/upload/contract/" + arraySrc[i].split(',')[]
no = i;
}
$("#imgsrc").attr('src', src);
$("#srcId").val(no);
}
}
})
//旋转
var num = ;
$("#rotate").click(function () {
num++;
$("#imgsrc").rotate(num * );
}) });
//放大缩小
function ImageSuofang(args) {
var imgsrc = document.getElementById("imgsrc");
if (args) {
imgsrc.width = imgsrc.width * 1.1;
imgsrc.height = imgsrc.height * 1.1;
}
else {
imgsrc.width = imgsrc.width / 1.1;
imgsrc.height = imgsrc.height / 1.1;
}
} </script>
3、Controller代码:js里 filedetail 的数据来源
public ActionResult DeviceEnclosureImgSeeForm()
{
FADeviceEnclosureModel DeviceEnclosureModel = new FADeviceEnclosureModel();
FADeviceEnclosure detail = DeviceEnclosureModel.Detail(int.Parse(Request["DeviceEnclosureId"]));
if (detail == null)
return Content("<script >alert('找不到信息!');window.parent.location.reload();</script >", "text/html"); DataTable dt = new DataTable();
dt.Columns.Add("ImgId");
dt.Columns.Add("fileSrc");
string[] DeviceEnclosureFileList = detail.DeviceEnclosureFile.Split(';'); for (int i = ; i < DeviceEnclosureFileList.Length; i++)
{
DataRow dr = dt.NewRow();
dr["ImgId"] = i;
dr["fileSrc"] = DeviceEnclosureFileList[i].ToString();
dt.Rows.Add(dr);
} ViewData["filedetail"] = dt; return View();
}
JQuery,JS图片操作(上一张,下一张,旋转,放大,缩小)的更多相关文章
- 分享图片压缩上传demo,可以选择一张或多张图片也可以拍摄照片
2016-08-05更新: 下方的代码是比较OLD的了,是通过js进行图片的剪切 旋转 再生成,效率较低. 后来又整合了一个利用native.js本地接口的压缩代码 ,链接在这 .页面中有详细的说明, ...
- jQuery模拟原生态App上拉刷新下拉加载
jQuery模拟原生态App上拉刷新下拉加载效果代码,鼠标上拉时会显示loading字样,并且会模拟加载一条静态数据,支持触屏设备使用. <!doctype html> <html ...
- 项目总结07:JS图片的上传预览和表单提交(FileReader()方法)
JS图片的上传预览和表单提交(FileReader()方法) 一开始没有搞明白下面这块代码的,今天有时间简单整理下 核心点:FileReader()方法 以下是代码(以JSP文件为例) <!DO ...
- js实现点击按钮实现上一张下一张相册滚动效果
/****判断图片是否构成滚动效果*/$(function(){ if($("#bar").find('img').size()*71<=$("#bar&qu ...
- .NET Core 图片操作在 Linux/Docker 下的坑
一.前言 .NET Core 目前更新到2.2了,但是直到现在在 .NET Core 本身依然不包括和图片有关的 Image.Bitmap 等类型.对于图片的操作在我们开发中很常见,比如:生成验证码. ...
- js 图片压缩上传(base64位)以及上传类型分类
一.input file上传类型 1.指明只需要图片 <input type="file" accept='image/*'> 2.指明需要多张图片 <input ...
- js 图片压缩上传(纯js的质量压缩,非长宽压缩)
下面是大神整理的demo,很实用,这里存一下备用,感谢大神! 此demo为大于1M对图片进行压缩上传 若小于1M则原图上传,可以根据自己实际需求更改. demo源码如下 <!DOCTYPE ht ...
- js图片压缩上传
最近公司的移动产品相约app要做一次活动,涉及到图片上传,图片又不能太大,不然用户体验太差,必须先压缩再上传,所以用到了html5的canvas和FileReader,代码先上,小弟前端经验不足,代码 ...
- JS框架_(JQuery.js)图片相册掀开切换效果
百度云盘 传送门 密码:y0dk 图片掀开切换效果: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN&quo ...
随机推荐
- netif_rx解析
netif_rx函数是在网上收到数据包后,通过中断机制通知CPU而间接调用的中断处理例程. 首先,会将Packet传给netpoll框架,该框架用于在网络协议栈不可用的情况下,也能够提供给内核一个收发 ...
- SQlite 学习资料
很有用的开源跨平台数据库,可以作为客户端的小型内存数据库使用,据说它有N多用户(Nokia's Symbian,Mozilla,Abobe,Google,阿里旺旺,飞信,Chrome,FireFo ...
- 第四记 Java异常
Java异常结构图 Java所有异常都是从Throwable继承而来,Throwable有两个子类,Error与Exception. Error是错误,对于所有的编译时期的错误以及系统错误都是通过Er ...
- 集合 HashMap 的原理,与 Hashtable、ConcurrentHashMap 的区别
一.HashMap 的原理 1.HashMap简介 简单来讲,HashMap底层是由数组+链表的形式实现,数组是HashMap的主体,链表则是主要为了解决哈希冲突而存在的,如果定位到的数组位置不含链表 ...
- python读取文件报错:pandas.errors.ParserError: iterator should return strings, not bytes (did you open the file in text mode?)
python 读取csv文件报错问题 import csv with open('E:/Selenium2script/DDT模块/test.csv','rb') as f: readers = cs ...
- 第十八天:CSV、JSON、Excel、SQLite
一.CSV文件 1.读取 reader = csv.reader(打开的file对象), reader为可迭代对象 2.用namedtuple映射列名 with open('apple.csv') a ...
- Linux的各个发行版本(二)
CentOS CentOS是世界上使用的最好的Linux服务器发行版之一,占了全世界Linux服务器的30%. 它是Red Hat 的衍生产品,提供了稳定的服务器环境. 特点: 支持的X86-64架构 ...
- bootstrap-自带插件(完成的小功能)
模态框 务必将模态框的HTML代码放在文档的最高层级内(也就是说,尽量作为 body 标签的直接子元素),以避免其他组件影响模态框的展现和/或功能. <!-- 触发模态框的按钮 --> & ...
- JS window对象取消计时器clearInterval() clearInterval() 方法可取消由 setInterval() 设置的交互时间。
取消计时器clearInterval() clearInterval() 方法可取消由 setInterval() 设置的交互时间. 语法: clearInterval(id_of_setInterv ...
- JavaScript中深拷贝实现
JavaScript 中深拷贝实现 拷贝时候涉及到: 1.循环结构 2.判断数组 Array 还是对象 Object 函数实现 /** * 获取满足条件的数组中的第一个元素 * @param ...