查看图片(类似微博发布图片的查看效果)

  1 <!DOCTYPE html>
  2 <html lang="en">
  3 <head>
  4   <title>imgBox</title>
  5   <style>
  6     *{list-style:none;}
  7   </style>
  8 </head>
  9 <body>
 10       <!-- 图片区 -->
 11       <div class="g-media-wrap clearfix" data-uic="uic">
 12         <div class="media-box">
 13           <ul class="g-media-a g-media-a-mn g-media-a-m9 clearfix" data-ncheck="one">
 14             <li class="g-pic">
 15               <img src="http://popup.freep.cn/images/freepupload.jpg" data-pcidaction="1" />
 16             </li>
 17             <li class="g-pic">
 18               <img src="http://popup.freep.cn/images/freepupload.jpg" data-pcidaction="2" />
 19             </li>
 20             <li class="g-pic">
 21               <img src="http://popup.freep.cn/images/freepupload.jpg" data-pcidaction="3" />
 22             </li>
 23             <li class="g-pic">
 24               <img src="http://popup.freep.cn/images/freepupload.jpg" data-pcidaction="4" />
 25             </li>
 26             <li class="g-pic">
 27               <img src="http://popup.freep.cn/images/freepupload.jpg" data-pcidaction="5" />
 28             </li>
 29             <li class="g-pic">
 30               <img src="http://popup.freep.cn/images/freepupload.jpg" data-pcidaction="6" />
 31             </li>
 32             <li class="g-pic">
 33               <img src="http://popup.freep.cn/images/freepupload.jpg" data-pcidaction="7" />
 34             </li>
 35             <li class="g-pic">
 36               <img src="http://popup.freep.cn/images/freepupload.jpg" data-pcidaction="8" />
 37             </li>
 38             <li class="g-pic">
 39               <img src="http://popup.freep.cn/images/freepupload.jpg" data-pcidaction="9" />
 40             </li>
 41           </ul>
 42         </div>
 43       </div>
 44       <div class="g-expand-media-box"></div>
 45       <!-- /图片区 -->
 46   <script type="text/javascript" src="http://libs.baidu.com/jquery/1.9.1/jquery.js"></script>
 47   <script type="text/javascript">
 48   function imgsee(mbox,mli){
 49         var lipar=‘‘; //9*9小图
 50         var bigpar=‘‘;//大图
 51         var index=0;
 52         var msgwid ,off,xx,yy;
 53         var l;
 54         // img和imgbox的各种属性
 55         var imgw
 56           var imgh;
 57         var imgboxw;
 58         var centerx;
 59         var centery;
 60         var imgtop;
 61         var imgboxtop;
 62         var imgleft;
 63         var imgboxleft;
 64         //num 旋转的计数
 65         var num=0;
 66         //小图li点击
 67          $(mbox).on(‘click‘,mli,function(){
 68            var addbox=‘<ul class="g-view-bar" style="height:30px;line-height:30px;">‘ +
 69             ‘<li class="up"><a href="javascript:void(0);"><i style="background-position:-221px -104px;"></i>收起</a></li>‘ +
 70             ‘<li class="big"><a href="javscript:void(0);" target="_blank"><i  style="background-position-241px -104px;"></i>查看大图</a></li>‘ +
 71             ‘<li class="to-left"><a href="javascript:void(0);"><i  style="background-position:-266px -103px;"></i>向左转</a></li>‘ +
 72             ‘<li class="to-right"><a href="javascript:void(0);"><i  style="background-position:-289px -103px;"></i>向右转</a></li>‘ +
 73             ‘</ul>‘ +
 74             ‘<div class="bigpic" style="position:relative;width:490px;overflow:hidden;vertical-align:middle;text-align:center;"> ‘+
 75             ‘<img src="" style="max-width:490px;min-width:100px;" /></div>‘ +
 76             ‘<div class="slist" style="width:490px;margin-top:5px; overflow:hidden;"></div>‘;
 77             lipar=$(this).parents(mbox);
 78             bigpar=lipar.next(‘.g-expand-media-box‘);
 79             index=$(this).index();
 80             bigpar.append(addbox);
 81             var bimgsrc=$(this).find(‘img‘).attr(‘src‘);  //大图src
 82             l = lipar.find(mli).length;
 83             bigpar.find("ul li").css({"float":"left","margin-left":"24px"});
 84             bigpar.find("ul li a").css({"color":"#ea5415"});
 85             var addhtml="<li><a href=‘javascript:;‘><img src=‘‘ /></a></li>";//添加li
 86             for(i=0;i<l;i++){
 87                 var allsrc=lipar.find(‘.g-media-a>li‘).eq(i).find(‘img‘).attr(‘src‘);
 88                 bigpar.find(‘.slist‘).append(addhtml);
 89                 bigpar.find(‘.slist>li‘).eq(i).find(‘a img‘).attr("src",allsrc);
 90               }
 91             bigpar.css(‘overflow‘,‘hidden‘);
 92             bigpar.find(".slist li").css({"float":"left","width":"54px","height":"54px"});
 93             bigpar.find(".slist li a.current").css({‘padding‘:‘0px‘,‘border‘:‘2px solid #eb7350‘});
 94             bigpar.find(".slist li a.current").css({"padding":"0px","width":"50px","height":"50px","display":"block",‘border‘:‘2px solid #eb7350‘});
 95             bigpar.find(".slist li a").hover(function(){
 96               $(this).css({‘padding‘:‘0px‘,‘border‘:‘2px solid #eb7350‘});
 97             },function(){
 98               bigpar.find(".slist li a").css({"padding":"2px","width":"50px","height":"50px","border":"0px"});
 99               bigpar.find(".slist li a.current").css({"padding":"0px","width":"50px","height":"50px","display":"block",‘border‘:‘2px solid #eb7350‘});
100             });
101             bigpar.find(".slist li img").css({"width":"50px","height":"50px"});
102             bigpar.find(‘.bigpic img‘).attr(‘src‘,bimgsrc);
103               bigpar.find(‘.slist li‘).eq(index).find(‘a‘).addClass(‘current‘);
104               bigpar.find(".slist li a.current").hover(function(){
105               bigpar.find(".slist li a.current").css({"padding":"0px","width":"50px","height":"50px","display":"block",‘border‘:‘2px solid #eb7350‘});
106             },function(){
107               $(this).css({"padding":"0px","width":"50px","height":"50px","display":"block",‘border‘:‘2px solid #eb7350‘});
108             });
109             lipar.hide().next(bigpar).show();
110          })
111          //收起
112         $(‘.g-expand-media-box‘).on(‘click‘,‘.g-view-bar li.up a‘,function(){
113           closePic($(this).parents(‘.g-expand-media-box‘));
114         });
115         //点击查看大图
116         $(‘.g-expand-media-box‘).on(‘click‘,‘.g-view-bar li.big‘,function(){
117           $(this).find(‘a‘).attr(‘href‘,$(this).parents(‘.g-expand-media-box‘).find(‘.bigpic img‘).attr(‘src‘));
118         });
119         //底部li点击事件
120           $(‘.g-expand-media-box‘).on(‘click‘,‘.slist li‘,function(){
121             index=$(this).index();
122             var listsrc=$(this).find(‘a img‘).attr(‘src‘);
123             showPic(index,$(this).find(‘a img‘).attr(‘src‘),$(this).parents(‘.g-expand-media-box‘));
124             $(this).find(‘a‘).addClass(‘current‘).parent(‘li‘).siblings(‘li‘).find(‘a‘).removeClass(‘current‘);
125           });
126           //划到图片上面的样式
127           $(‘.g-expand-media-box‘).on(‘mousemove‘,‘.bigpic img‘,function(e){
128             msgwid=$(this).width()/3;
129             num=$(this).attr(‘data-name‘);
130             if(num == -1 || num == -3){
131               msgwid=$(this).height()/3;
132             }
133             off=$(e.target).offset();
134             leftoff=off.left;
135             xx=e.pageX-leftoff;
136             //判断鼠标的位置
137             if(xx < msgwid){
138               $(this).removeClass(‘smallcursor rightcursor‘).addClass(‘leftcursor‘);
139             }else if(xx >= msgwid && xx < msgwid *2){
140               $(this).removeClass(‘leftcursor rightcursor‘).addClass(‘smallcursor‘);
141             }else{
142               $(this).removeClass(‘leftcursor smallcursor‘).addClass(‘rightcursor‘);
143             }
144             $(‘.leftcursor‘).css({"cursor":"url(http://img.t.sinajs.cn/t6/style/images/common/pic_prev.cur), auto"});
145           $(‘.smallcursor‘).css({"cursor":"url(http://img.t.sinajs.cn/t6/style/images/common/small.cur), auto"});
146           $(‘.rightcursor‘).css({"cursor":"url(http://img.t.sinajs.cn/t6/style/images/common/pic_next.cur), auto"});
147           });
148
149           //点击图片的改变
150           $(‘.g-expand-media-box‘).on(‘click‘,‘.bigpic‘,function(e){
151             //点击的位置之后的效果
152             l=$(this).parents(‘.g-expand-media-box‘).find(‘.slist>li‘).length;
153             //获取index
154             $(this).parents(‘.g-expand-media-box‘).find(‘.slist li ‘).each(function(e){
155               if($(this).find(‘a‘).attr(‘class‘)==‘current‘){
156                 index=e;
157               }
158             })
159           if(xx < msgwid){
160             if(index == 0){
161               alert(‘已经到第一张图片了‘);
162             }else{
163               if($(this).find(‘img‘).is(‘:animated‘)){
164                   return;
165                 }
166               index--;
167               $(this).siblings(‘.slist‘).find(‘li‘).eq(index).trigger(‘click‘);
168             }
169             }else if(xx >= msgwid && xx < msgwid *2){
170               closePic($(this).parents(‘.g-expand-media-box‘));
171               closero($(this).parents(‘.g-expand-media-box‘));
172             }else{
173               if(index == l-1){
174                 alert(‘已经到最后一张图片了‘);
175             }else{
176               if($(this).find(‘img‘).is(":animated")){
177                   return;
178                 }else{
179                   index++;
180                   $(this).siblings(‘.slist‘).find(‘li‘).eq(index).trigger(‘click‘);
181                 }
182             }
183             }
184         })
185         //向左转
186           $(‘.g-expand-media-box‘).on(‘click‘,‘.g-view-bar li.to-left‘,function(){
187             //取没有转换之前的w,h
188             var thbox=$(this).parents(‘.g-expand-media-box‘);
189             var fd=thbox.find(‘.ropates‘).attr(‘class‘);
190             if(fd == undefined){
191               var removesrc = thbox.find(‘.bigpic img‘).attr(‘src‘);
192               thbox.find(‘.bigpic img‘).remove();
193               thbox.find(‘.bigpic‘).append("<div class=‘ropates‘> <img src=‘‘ data-name=‘0‘ /></div>");
194               thbox.find(‘.bigpic .ropates img‘).attr(‘src‘,removesrc);
195             }
196             num=thbox.find(‘.ropates img‘).attr(‘data-name‘);
197           num--;
198           if(num == -4 ){
199             num = 0;
200           }
201           thbox.find(‘.ropates img‘).attr(‘data-name‘,num);
202           imgPos(num,thbox.find(‘.ropates‘),thbox.find(‘.ropates img‘));
203         });
204
205           //向右转
206           $(‘.g-expand-media-box‘).on(‘click‘,‘.g-view-bar li.to-right‘,function(){
207             //取没有转换之前的w,h
208             var thbox=$(this).parents(‘.g-expand-media-box‘);
209             var fd=thbox.find(‘.ropates‘).attr(‘class‘);
210             if(fd == undefined){
211               var removesrc = thbox.find(‘.bigpic img‘).attr(‘src‘);
212               thbox.find(‘.bigpic img‘).remove();
213               thbox.find(‘.bigpic‘).append("<div class=‘ropates‘> <img src=‘‘ data-name=‘0‘ /></div>");
214               thbox.find(‘.bigpic .ropates img‘).attr(‘src‘,removesrc);
215             }
216             num=thbox.find(‘.ropates img‘).attr(‘data-name‘);
217             num++;
218             if(num == 1 ){
219             num = -3;
220           }
221             thbox.find(‘.ropates img‘).attr(‘data-name‘,num);
222           imgPos(num,thbox.find(‘.ropates‘),thbox.find(‘.ropates img‘));
223         });
224
225           //转换调用,thro,thimg,分别是父级和img
226         function imgPos(num,thro,thimg){
227           switch(num){
228             case 0:
229               thimg.css({‘transform‘:‘matrix(1,0,0,1,0,0)‘,‘position‘:‘absolute‘,‘height‘:‘auto‘});
230               ioffset(thimg);
231               thro.css({‘height‘:imgh});
232               thimg.css({‘top‘:‘0px‘,‘left‘:centerx});
233               break;
234             case -1:
235               //转换的高度等于之前的宽度
236               thimg.css({‘transform‘:‘matrix(0, -1, 1, 0, 0, 0)‘,‘position‘:‘absolute‘,‘max-width‘:‘490px‘});
237               imgh=thimg.height();
238               imgboxw=thro.width();
239               if(imgh > imgboxw){
240                 thimg.height(imgboxw);
241               }
242               //取两次img的高度,
243               ioffset(thimg);
244               var noww=thimg.width();
245               //取现在的宽度给box设定高度
246               thro.css({‘height‘:noww});
247               thimg.css({‘top‘:imgboxtop-imgtop,‘left‘:imgboxleft-imgleft+centery});
248               break;
249             case -2:
250               thimg.css({‘transform‘:‘matrix(-1, 0, 0, -1, 0, 0)‘,‘position‘:‘absolute‘,‘height‘:‘auto‘});
251               ioffset(thimg);
252               thro.css({‘height‘:imgh});
253               thimg.css({‘top‘:‘0px‘,‘left‘:centerx});
254               break;
255             case -3:
256               thimg.css({‘transform‘:‘matrix(0, 1, -1, 0, 0, 0)‘,‘position‘:‘absolute‘,‘max-width‘:‘490px‘});
257               imgh=thimg.height();
258               imgboxw=thro.width();
259               if(imgh > imgboxw){
260                 thimg.height(imgboxw);
261               }
262               //取两次img的高度,
263               ioffset(thimg);
264               var noww=thimg.width();
265               //取现在的宽度给box设定高度
266               thro.css({‘height‘:noww});
267               thimg.css({‘top‘:imgboxtop-imgtop,‘left‘:imgboxleft-imgleft+centery});
268               break;
269           }
270           //现在img and imgbox的属性
271           function ioffset(thimg){
272             thimg.css({‘top‘:‘0px‘,‘left‘:‘0px‘});
273             imgh=thimg.height();
274             imgw=thimg.width();
275             centery=(imgboxw-imgh) /2;
276             centerx=(imgboxw-imgw)/2;
277             //取img,imgbox距离top,left,方向的距离
278             imgtop=thimg.offset().top;
279             imgboxtop=thro.offset().top;
280             imgleft=thimg.offset().left;
281             imgboxleft=thro.offset().left;
282           }
283         }
284         //图片渐显
285         function showPic(index,listsrc,obj){
286             obj.find(‘.bigpic img‘).fadeTo(100,0.6,function(){
287                 closero(obj);
288                 obj.find(‘.bigpic img‘).attr(‘src‘,listsrc);
289             }).fadeTo(100,1);
290           }
291         //关闭旋转
292           function closero(obj){
293             var fd=obj.find(‘.ropates‘).attr(‘class‘);
294             if(fd == ‘ropates‘){
295             var removesrc =obj.find(‘.ropates img‘).attr(‘src‘);
296             obj.find(‘.ropates‘).remove();
297             obj.find(‘.bigpic‘).append("<img src=‘ ‘ />");
298             obj.find(‘.bigpic img‘).attr(‘src‘,removesrc);
299             num =0;
300           }
301           }
302           //关闭大图
303           function closePic(obj){
304             obj.empty().hide().prev().show();
305           }
306       }
307       imgsee(‘.g-media-wrap‘,‘.media-box ul li‘);
308   </script>
309 </body>
310 </html>
时间: 2024-07-29 20:00:33

查看图片(类似微博发布图片的查看效果)的相关文章

jQuery实现的点击图片放大且在当前页面查看原图

jquery在当前页面查看原图,单击图片,显示出大图片,再次单击图片,恢复网页原有状态.不刷新页面的情况下查看原图,在网上类似的应用有很多.有时候朋友们说这是无刷新放大图片的功能,其实也就那么一回事吧,不过从本款代码来看,这功能实现起来并不太复杂,引入了jQuery,代码分享给大家. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DT

图片预览、画廊、查看、幻灯片插件

当年面对这样一个效果的时候,真是蛋疼,觉得自己尼玛出来还能靠这个吃饭嘛,唏嘘叹惋之余还是坚定信心,很多人都看不起你能做这一行(我特妈自己也不信),当你认真的做一件事时,自己都觉得可怕,加油吧,没什么能阻止你认真.老罗说的好:我尼玛不在乎输赢,我就是特么认真. 但是今年自己遇到很多事,总是不能安心,所以今天试着格式化自己,认真的写了这个以前让我蛋疼的插件. DEMO: 调用方法: <head> <script type="text/javascript" src=&qu

iOS12系统图片heic如何在电脑上查看

说到iOS12系统,只有iPhone用户应该比较熟悉些,对于安卓用户来说都会比较陌生的,而且其系统的图片格式也是比较独特的,在电脑上是无法直接查看的,那iOS12系统图片heic如何在电脑上查看呢? 1.在电脑上运行苹果HEIC图片转换器,可以将手机中的heic格式传到电脑中,如果较好的情况下,最好新建一个文件夹批量保存转换:2.打开转换器,需要先添加文件,即iPhone拍出来的照片,可以批量添加图片,点击"添加图片"即可添加:3.HEIC格式图片添加之后,点击输出目录后面的三个点按钮

在Windows7中打开照片,提示“Windows 照片查看器无法显示此图片,因为计算机上的可用内存可能不足。....”

在Windows7中打开照片,提示“Windows 照片查看器无法显示此图片,因为计算机上的可用内存可能不足.请关闭一些目前没有使用的程序或者释放部分硬盘空间(如果硬盘几乎已满),然后重试.” 如下图所示: 处理过程: 1.查看计算机的内存和磁盘空间是否足够.  总内存为4GB,只使用40%:每个分区的磁盘空间都有几十个G.(资源足够) 2.查看图片是否已损坏.  图片在别的电脑能打开,或者在本机使用“画图”功能也能打开. (未损坏) 经发现,使用Windows照片查看器打开电脑中存在的图片,不

怎么编写微博爬虫 图片爬虫

背景:实验室大数据分析需要得到社交网站的数据,首选当然是新浪.数据包括指定关键词.话题.位置的微博的内容.字段包括:图片.时间.用户.位置信息. 思路分析:要爬新浪的数据主要有2种方法: 1.微博开发者平台提供的微博API,资源包括微博内容.评论.用户.关系.话题等信息.同时,你也可以申请高级接口.商业接口获得更多权限,你要去注册申请成为开发者获得OAuth2授权以及这个使用参考,审核大约要1周.也可以直接使用别人分享的APPKEY. 优点是简单,有专门的问答社区,代码更新方便,可以获得real

利用WebService发布图片文件

服务器端: 1.新建一个Asp.net空网站RGImageServer 2.新建一个WebService项目ImageService,项目新增文件ImageService.asmx,添加方法GetTile(). 1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Web; 5 using System.Web.Services; 6 using System.IO; 7 u

本地与在线图片转Base64及图片预览

查看效果:http://sandbox.runjs.cn/show/tgvbo9nq 本地图片转Base64(从而可以预览图片): function localImgLoad() { var src = this.files[0]; var self = $(this); var read = new FileReader(); read.onload = function(e) { var html = "<img src=" + e.target.result + "

java实现批量下载百度图片搜索到的图片

就是写的个小程序,用于记录一下,方便后续查看,首先感谢下面这个博客,从这篇文章衍生的吧,大家可以学习下: http://www.cnblogs.com/lichenwei/p/4610298.html 读了这边文章,觉得很有意思,就模仿着写了个,从百度图片所有并下载到本地,主要思路是一样的. 贴下代码: package com.guo.common; import java.io.BufferedReader; import java.io.BufferedWriter; import java

在viewPager中双指缩放图片,双击缩放图片,单指拖拽图片

我们就把这个问题叫做图片查看器吧,它的主要功能有: 1.双击缩放图片. 2. 双指缩放图片. 3.单指拖拽图片. 为此这个图片查看器需要考虑以下的技术点: 一.双击缩放图片: 1.如果图片高度比屏幕的高度小得多,那么就将图片放大到高度与屏幕高度相等,否则就放大一个特定的倍数. 2.如何判断是否到达这个倍数来停止缩放. 3.判断完且停止放大后,图片可能已经超出了这个倍数需要的大小,如何回归到我们的目标大小. 4.判断完且停止缩小后,图片宽度可能已经小于屏幕宽度,在两边留下了空白,如何重置为原来的大