图片浏览 h5
@{
Layout = null;
}
<html>
<head>
<script type="text/javascript" src="~/scripts/jquery-1.10.2.min.js"></script>
<meta name="viewport" content="width=device-width,height=device-height, minimum-scale=0.1">
<style>
img {
text-align: center;
position: absolute;
margin: auto;
top: ;
right: ;
bottom: ;
left: ;
}
.overflowingVertical {
cursor: zoom-out;
}
.shrinkToFit {
cursor: zoom-in;
}
body {
background-color: #;
color: #eee;
margin: ;
}
</style>
</head>
<body>
<img src="@ViewBag.PicURL" alt="@ViewBag.PicURL" onload="initImg();" />
<script>
function initImg() {
drawImage($("img"), document.body.clientWidth, document.body.clientHeight);
}
function drawImage(ImgD, FitWidth, FitHeight) {
var image = new Image();
image.src = ImgD.attr("src");
if (image.width > && image.height > ) {
if (image.width / image.height >= FitWidth / FitHeight) {
if (image.width > FitWidth) {
ImgD.css("width", FitWidth);
ImgD.css("height", (image.height * FitWidth) / image.width);
$("img").attr("class", "shrinkToFit");
ImgD.css("margin-top", );
} else {
ImgD.css("width", image.width);
ImgD.css("height", image.height);
}
} else {
if (image.height > FitHeight) {
ImgD.css("height", FitHeight);
ImgD.css("width", (image.width * FitHeight) / image.height);
$("img").attr("class", "shrinkToFit");
ImgD.css("margin-top", );
} else {
ImgD.css("width", image.width);
ImgD.css("height", image.height);
}
}
}
}
$("img").mousedown(function () {
if (typeof $(this).attr("class") != "undefined") {
$(this).toggleClass("shrinkToFit overflowingVertical");
if ($(this).hasClass("overflowingVertical")) {
var img = new Image();
img.src = $(this).attr("src");
var imgWidth = img.width; //图片实际宽度
var imgHeight = img.height; //图片实际高度
drawImage($(this), imgWidth, imgHeight);
}
if ($(this).hasClass("shrinkToFit")) {
drawImage($("img"), document.body.clientWidth, document.body.clientHeight);
}
}
});
</script>
</body>
</html>
后台:
/// <summary>
/// 图片自适应居中打开,非图片浏览器下载
/// </summary>
/// <param name="dirRelativePath">文件路径,包含文件名</param>
/// <param name="fileName">文件名</param>
/// <returns></returns>
public ActionResult OpenPicture(string dirRelativePath, string fileName)
{
Regex regex = new Regex(@"\.jpg|\.bmp|\.png|\.gif|\.tiff");
fileName = fileName.ToLower();
var isMatch = regex.IsMatch(fileName);
//图片
if (isMatch)
{
ViewBag.PicURL = "/Home/DownLoad?dirRelativePath=" + dirRelativePath + "&fileName=" + fileName;
}
else
{
return RedirectToAction("DownLoad", "Home", new { dirRelativePath = dirRelativePath, fileName = fileName });
}
return View();
}
/// <summary>
/// 下载附件
/// </summary>
/// <param name="dirRelativePath"></param>
/// <param name="fileName"></param>
/// <returns></returns>
public ActionResult DownLoad(string dirRelativePath, string fileName)
{ string uploadPath = System.Configuration.ConfigurationManager.AppSettings["BPMAttachments"];
string dirAbsolutePath = uploadPath + dirRelativePath; if (!System.IO.File.Exists(dirAbsolutePath))
{
return Content("提示:文件在磁盘上不存在");
}
//HttpContext.Response.AddHeader("content-disposition", "attachment;filename=" + fileName);
//return File(dirAbsolutePath, "application/octet-stream");
var contentType = MimeMapping.GetMimeMapping(fileName);
HttpContext.Response.AddHeader("content-disposition", "inline;filename=" + fileName);
return File(dirAbsolutePath, contentType);
}
图片浏览 h5的更多相关文章
- 图片浏览(CATransition)转场动画
Main.storyboard ViewController.m // // ViewController.m // 8A04.图片浏览(转场动画) // // Created by huan ...
- Android 高级UI设计笔记14:Gallery(画廊控件)之 3D图片浏览
1. 利用Gallery组件实现 3D图片浏览器的功能,如下: 2. 下面是详细的实现过程如下: (1)这里我是测试性代码,我的图片是自己添加到res/drawable/目录下的,如下: 但是开发中不 ...
- 用CSS和第三方库来提升图片浏览体验
你是否关注过浏览.点击图片这个微妙的过程,不同的图片展现.交互方式各带来什么样的观感?本文聚焦于图片浏览这个过程以及如何使用CSS3和第三方库来提升体验. 先看下Pinterest.Flickr等时下 ...
- 第17讲- UI常用组件之ImageView图片浏览
第17讲 UI常用组件之ImageView图片浏览 二.图片浏览ImageView ImageView就是一个用来显示图片的视图: ImageView常见属性 常见属性 对应方法 说明 android ...
- [置顶] ios 一个不错的图片浏览分享框架demo
demo功能:一个不错的图片浏览分享框架demo.iphone6.1 测试通过.可以浏览图片,保存,微博分享到新浪,腾讯,网易,人人等. 注:(由于各个微博的接口有时候会有调整,不一定能分享成功.只看 ...
- WPF 图片浏览 伪3D效果
原文:WPF 图片浏览 伪3D效果 首先上效果图: 因项目要求,需要把图片以"好看"."炫"的效果展示出来,特地研究了一下WPF关于3D方面的制作,奈何最终成果 ...
- Ubuntu下几个命令行方式使用的图片浏览工具
想找几个Ubuntu下可以以命令行方式使用的图片浏览工具. Google了一些资料,找到下面几个web: 1.pho:轻巧的命令行图片查看器 其中介绍了工具pho,其功能特点,见下面的转帖内容: ph ...
- 【MVC】快速构建一个图片浏览网站
当抄完MusicStore时,你应该对MVC有一个比较清晰的认识了.接下来就需要做个网站来继续增加自己的知识了.那么,该做个什么网站呢.做个图片浏览网站吧,简单而实用. 简单设计 1.首先,页面中间是 ...
- iOS Swift WisdomScanKit二维码扫码SDK,自定义全屏拍照SDK,系统相册图片浏览,编辑SDK
iOS Swift WisdomScanKit 是一款强大的集二维码扫码,自定义全屏拍照,系统相册图片编辑多选和系统相册图片浏览功能于一身的 Framework SDK [1]前言: 今天给大家 ...
随机推荐
- PHP实现跨域解决方法
如果要实现跨域通过设置Access-Control-Allow-Origin来实现跨域. 例如:客户端的域名是client.runoob.com,而请求的域名是server.runoob.com. 如 ...
- CJOJ 2255 【NOIP2016】组合数问题 / Luogu 2822 组合数问题 (递推)
CJOJ 2255 [NOIP2016]组合数问题 / Luogu 2822 组合数问题 (递推) Description 组合数\[C^m_n\]表示的是从n个物品中选出m个物品的方案数.举个例子, ...
- Ambari安装之部署3个节点的HA分布式集群
前期博客 Ambari安装之部署单节点集群 其实,按照这个步骤是一样的.只是按照好3个节点后,再做下HA即可. 部署3个节点的HA分布式集群 (1)添加机器 和添加服务的操作类似,如下图 之后的添加a ...
- 通过添加filter过滤器 彻底解决ajax 跨域问题
1.在web.xml添加filter <filter> <filter-name>contextfilter</filter-name> <filter-cl ...
- (转)Linux命令grep
场景:grep命令在文件搜索中经常会使用到,所以熟练掌握该命令对于日常日志搜索相当有必要! Linux系统中grep命令是一种强大的文本搜索工具,它能使用正则表达式搜索文本,并把匹 配的行打印出来.g ...
- Object-C 里面的animation动画效果,核心动画
#import "CoreAnimationViewController.h" @interface CoreAnimationViewController ()@property ...
- 【CSS3】块级元素与行内元素的区别
一.行内元素与块级函数的三个区别 行内元素的特点: 和其他元素都在一行上: 高,行高及外边距和内边距部分可改变: 宽度只与内容有关: 行内元素只能容纳文本或者其他行内元素. 行内元素设置width无效 ...
- MySQL学习笔记(四):存储引擎的选择
一:几种常用存储引擎汇总表 二:如何选择 一句话:除非需要InnoDB 不具备的特性,并且没有其他办法替代,否则都应该优先考虑InnoDB:或者,不需要InnoDB的特性,并且其他的引擎更加合适当前情 ...
- VM虚拟机中安装Linux操作系统
本文操作步骤,笔者已实验成功 (前提:正确安装VM并激活) 1,点击新建虚拟机,在页面上选择"自定义",点击下一步 2,进入选择虚拟机硬件兼容页面,这里一般不用操作,直接点击下一步 ...
- 解决Ubuntu手动安装vim后无法正常…
首先声明这个问题很坑爹~ 问题描述:下载了vim7.3版本的源码,在虚拟机里面的ubuntu12中手动安装成功后.在使用vim编辑文档时,进入编辑模式出现如下现象:1.使用方向键会打印出"A ...