移动端点击图片查看大图

一、需求

点击图片查看大图,再点大图隐藏。多用于移动端,因为移动端屏幕小,可能需要查看大图。

二、代码

<!DOCTYPE html>
<html>
<meta charset="utf-8"/>
<head runat="server">
<title>JQuery点击图片查看大图by starof</title>
<style type="text/css">
.exampleImg { height:100px; cursor:pointer;}
</style>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript">
//alert($);
// (function (window, undefined) {
// var MyJQuery = function () {
// window.MyjQuery = window.$ = jQuery; window.$ = MyJQuery;
// };
// })(window);
// alert($);

$.fn.ImgZoomIn = function () {

bgstr = '<div id="ImgZoomInBG" style=" background:#000000; filter:Alpha(Opacity=70); opacity:0.7; position:fixed; left:0; top:0; z-index:10000; width:100%; height:100%; display:none;"><iframe src="about:blank" frameborder="5px" scrolling="yes" style="width:100%; height:100%;"></iframe></div>';
//alert($(this).attr('src'));
imgstr = '<img id="ImgZoomInImage" src="' + $(this).attr('src')+'" onclick=$(\'#ImgZoomInImage\').hide();$(\'#ImgZoomInBG\').hide(); style="cursor:pointer; display:none; position:absolute; z-index:10001;" />';
if ($('#ImgZoomInBG').length < 1) {
$('body').append(bgstr);
}
if ($('#ImgZoomInImage').length < 1) {
$('body').append(imgstr);
}
else {
$('#ImgZoomInImage').attr('src', $(this).attr('src'));
}
//alert($(window).scrollLeft());
//alert( $(window).scrollTop());
$('#ImgZoomInImage').css('left', $(window).scrollLeft() + ($(window).width() - $('#ImgZoomInImage').width()) / 2);
$('#ImgZoomInImage').css('top', $(window).scrollTop() + ($(window).height() - $('#ImgZoomInImage').height()) / 2);
$('#ImgZoomInBG').show();
$('#ImgZoomInImage').show();
};

$(document).ready(function () {
$("#imgTest").bind("click", function () {
$(this).ImgZoomIn();
});
});
</script>
</head>
<body>
<div>
<!--第一种写法-->
<img class="exampleImg" src="images/03.jpg" id="imgTest"/>
<!--第二种写法-->
<img class="exampleImg" src="images/p1_nav2.png" onClick="$(this).ImgZoomIn();"/>
</div>
</body>
</html>

 

三、技巧

需要点击图片中1、2、3、4四张小图分别查看大图,而下面左右按钮切换时是需要同时切换4张小图。

因为移动端无法添加热点,最终一个解决方法是使用四个a标签定位到左上角,右上角,左下角,右下角四个区域。

<dl>
  <dd style="display:block;">
      <img src="images/four-duche.jpg" onClick="$(this).ImgZoomIn();">
      <a href="javascript:;" src="images/11.jpg" class="topleft" onClick="$(this).ImgZoomIn();"></a>
      <a href="javascript:;" src="images/12.jpg" class="topright" onClick="$(this).ImgZoomIn();"></a>
      <a href="javascript:;" src="images/13.jpg" class="bottomleft" onClick="$(this).ImgZoomIn();"></a>
      <a href="javascript:;" src="images/14.jpg" class="bottomright" onClick="$(this).ImgZoomIn();"></a>
    </dd>
    ...
</dl>

css

.topleft,.topright,.bottomleft,.bottomright{
    width:50%;
    height:50%;
    position:absolute;
}

.topleft{
    /*background-color:red;*/
    top:0;
    left:0;
}
.topright{
    /*background-color:green;*/
    top:0;
    right:0;
}
.bottomleft{
    /*background-color:blue;*/
    bottom:0;
    left:0;
}
.bottomright{
    /*background-color:yellow;*/
    bottom:0;
    right:0;
}

 

本文作者starof,因知识本身在变化,作者也在不断学习成长,文章内容也不定时更新,为避免误导读者,方便追根溯源,请诸位转载注明出处:http://www.cnblogs.com/starof/p/4924822.html有问题欢迎与我讨论,共同进步。

时间: 2024-08-29 13:22:53

移动端点击图片查看大图的相关文章

jquery实现移动端点击图片查看大图特效_jquery

本文的需求很简单:点击图片查看大图,再点大图隐藏.多用于移动端,因为移动端屏幕小,可能需要查看大图. 具体实现代码 <!DOCTYPE html> <html> <meta charset="utf-8"/> <head runat="server"> <title>JQuery点击图片查看大图by starof</title> <style type="text/css&quo

基于JavaScript实现移动端点击图片查看大图点击大图隐藏_javascript技巧

一.需求 点击图片查看大图,再点大图隐藏.多用于移动端,因为移动端屏幕小,可能需要查看大图. 二.代码 <!DOCTYPE html> <html> <meta charset="utf-8"/> <head runat="server"> <title>JQuery点击图片查看大图by starof</title> <style type="text/css">

Android 实现WebView点击图片查看大图列表及图片保存功能

在日常开发过程中,有时候会遇到需要在app中嵌入网页,此时使用WebView实现效果,但在默认情况下是无法点击图片查看大图的,更无法保存图片.本文将就这一系列问题的实现进行说明. 图示: 项目的知识点: 加载网页后如何捕捉网页中的图片点击事件: 获取点击的图片资源后进行图片显示,获取整个页面所有的图片: 支持查看上下一张的图片以及对图片缩放显示: 对图片进行保存: 其他:图片缓存的处理(不用每次都重新加载已查看过的图片) 项目代码结构: 前期准备(添加权限.依赖和混淆设置): 添加权限: <us

移动端点击图片放大特效PhotoSwipe.js插件实现_javascript技巧

PhotoSwipe插件能实现手机端点击图片全屏放大 再双击图片放大等功能 PhotoSwipe插件官方网站 http://www.photoswipe.com/ photoswipe之移动端图片放大查看,滑动切换下一张,图片保存到本地. <style> .pnav{margin-top:30px;text-align:center;line-height:24px; font-size:16px} .pnav a{padding:4px} .pnav a.cur{background:#00

手机端点击图片放大特效PhotoSwipe.js插件实现_javascript技巧

PhotoSwipe插件能实现手机端点击图片全屏放大 再双击图片放大等功能 PhotoSwipe插件官方网站 http://www.photoswipe.com/ 但有一点不太好的是图片放大后再单击不能关闭浏览,要点击关闭按钮或者滑动才能关闭,找了好久配置项都没说到这点上的,只能自己动手改了. 打开photoswipe.js,大概在3179行有个关于tap的函数定义 在开头先定义一个变量 var tap_num = 0; 然后在onTapStart的定义里加入 //根据需求自己添加的S //判断

jQuery实现点击小图查看大图功能

演示地址:点击查看  前两天用Js实现在这个功能,现在在学习JQuery 也做了一下这个功能,多多练习,一切都会变的简单:    <!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

jQuery实现点击小图显示大图代码分享_jquery

本文实例讲述了jQuery实现点击小图显示大图效果.分享给大家供大家参考.具体如下: 这是一款基于jQuery实现的点击小图查看大图的代码,适合用于产品展示等环节,便于用户浏览产品细节,是一款非常实用的特效代码. 运行效果图:    ----------------------查看效果-----------------------   小提示:浏览器中如果不能正常运行,可以尝试切换浏览模式. 为大家分享的jQuery实现点击小图显示大图效果代码如下 <head> <title>jQ

win10设置默认图片查看器

win10默认的图片查看器很不好用,主要是打开的时候反应太慢,没有win7时那么快.下面我就简单介绍下如何更改win10默认的图片查看器 首先打开开启菜单,键盘快捷键打开或者桌面左下角图标点击打开都可以 点击图中箭头所指的设置 这里可以看到很多选项,点击系统,就是图中的箭头所指的地方 在左边菜单栏找到默认应用选项 然后可以看到一些已经设置好的默认应用,可以看到图片查看器默认的应用是win10提供的新的查看器 点击图片查看器下的图标,这时候会列出所有可设置的图片查看器软件,选择图中箭头指的那个查看

ios在群里发的图片,android端点击放大显示不出来

问题描述 **ios在群里发的图片,android端点击放大显示不出来** 解决方案 ios和android是互通的,图片看大图是没问题的,点击会先下载下来