网页中商品图片的局部放大效果

需求背景:购物网站中的商品局部放大:

代码:

html:

<div class="Pro_Detleft">

<div class="detail-itemsummary-imageviewer">

<div id="middlePicRemark" class="middlePicRemark">  <img id="imgGoodsPic" alt="" src="images/20141009154623153.jpg" style="width:950px; height:950px; display:block;position: relative"></div>

<div id="middlePicBox" class="middlePicBox">

<span id="BigViewImage" class="jqzoom" style="outline-style: none; cursor: crosshair; display: block; position: relative; height: 396px; width: 396px;"><img id="" style="width: 396px; height: 396px; position: absolute; top: 0px; left: 0px;"
src="images/20141009154623153.jpg">

<div class=‘jqZoomPup‘ style=‘height:166.32px;width: 214.240837696335px;border-width: 1px;visibility: hidden;position: absolute;‘>

</div></span>

</div>

css:

.middlePicRemark {

position: absolute;

top: 0;

left: 0;

width: 244px;

z-index: 1;

line-height: 18px;

text-align: center;

padding: 3px;

background-color: #f3f3f3;

border: 1px #999 solid;

display: none;

}

.middlePicBox {

clear: both;

PADDING-BOTTOM: 0;

HEIGHT: 396px;

TEXT-ALIGN: center;

border: 1px solid #E3E3E3;

position: relative;

}

.middlePicBox i.F_goods_xg {

display: block;

width: 77px;

height: 77px;

position: absolute;

top: 28px;

left: 28px;

z-index: 5;

}

.middlePicBox {

clear: both;

PADDING-BOTTOM: 0;

HEIGHT: 396px;

TEXT-ALIGN: center;

border: 1px solid #E3E3E3;

position: relative;

}

.jqZoomPup {

overflow: hidden;

background-color: #FFF;

-moz-opacity: 0.6;

opacity: 0.6;

filter: alpha(opacity = 60);

z-index: 10;

border-color: #e3e3e3;

border-style: solid;

cursor: crosshair;

}

js:

//鼠标在大图上移动时局部放大

/*

* 算法思路是用两个图片,一个为鼠标在其上移动的小图,另一个为大图,动态获取鼠标的位置,在小图上的偏移量成比例的移动大图,使其部分显示在div中达到放大效果

*

* */

$("#BigViewImage").mousemove(function(e){

var divObj=document.getElementById("middlePicBox");//获取外层span在整个页面的偏移量

var curX= e.pageX-GetObjPos(divObj)[‘x‘];           //获取鼠标相对于大图片左上角的偏移量

var curY= e.pageY-GetObjPos(divObj)[‘y‘];

if(curX<107.12)curX=107.12;                          //如果小图片左上角到达大图片左上角,则停止移动

if(curX>288.88)curX=288.88;

if(curY<83.16)curY=83.16;

if(curY>312.84)curY=312.84;

var percentX=(curX-107.12)/396;

var percentY=(curY-83.16)/396;   //当前小矩形框的左上角偏移量相对于图片的横向比例

var BigViewOffsetX=percentX*950;      //计算出右边放大图应该放大的偏移量

var BigViewOffsetY=percentY*950;

$("#middlePicRemark").css(‘display‘,‘block‘);

$(‘.jqZoomPup‘).css(‘left‘,curX-107.12+‘px‘);

$(‘.jqZoomPup‘).css(‘top‘,curY-83.16+‘px‘);

$(".jqZoomPup").css(‘visibility‘,‘visible‘);

$("#imgGoodsPic").css(‘left‘,0-BigViewOffsetX+‘px‘);

$("#imgGoodsPic").css(‘top‘,0-BigViewOffsetY+‘px‘);

}).mouseout(function(){

$(".jqZoomPup").css(‘visibility‘,‘hidden‘);

$("#middlePicRemark").css(‘display‘,‘none‘);

});

时间: 2024-08-05 22:42:47

网页中商品图片的局部放大效果的相关文章

imagesLoaded – 检测网页中的图片是否加载

imagesLoaded 是一个用于来检测网页中的图片是否载入完成的 JavaScript 工具库.支持回调的获取图片加载的进度,还可以绑定自定义事件.可以结合 jQuery.RequireJS 使用. 插件下载     效果演示 使用示例: // element imagesLoaded( document.querySelector('#container'), function( instance ) { console.log('all images are loaded'); });

网页中的图片查看器viewjs使用

需求分析: 对于网页中的图片进行连续放大(便于用户清晰查看内容).缩小,旋转等操作,可以使用viewjs图片查看器插件实现. viewjs官方网址:https://github.com/fengyuanchen/viewerjs 具体使用方法请参照官网说明. 下面做2个简单的示例: 1.示例一:单一图片 1 <!DOCTYPE html> 2 <html lang="zh"> 3 4 <head> 5 <meta charset="U

下载网页中的图片到本地

简单的一个下载如下 : string url = "http://avatar.csdn.net/A/2/6/2_yefengzhixia.jpg"; string filepath = "D:\\pic.jpg"; WebClient mywebclient = new WebClient(); mywebclient.DownloadFile(url, filepath); MessageBox.Show("OK"); 下面演示一个从网站中下

Python抓取网页中的图片到本地

今天在网上找了个从网页中通过图片URL,抓取图片并保存到本地的例子: 1 #!/usr/bin/env python 2 # -*- coding:utf-8 -*- 3 4 # Author: xixihuang 5 # Date : 2016/08/28 10:12 AM 6 # Desc: 抓取网页,获取图片URL,抓取图片内容并保存到本地. 7 8 import os 9 import uuid 10 import urllib2 11 import cookielib 12 '''获取

[python][爬虫]从网页中下载图片

说明:仅为测试下载图片.正则表达式 测试url为钢铁侠贴吧的一个介绍mark各代盔甲帖子 以下代码将第一页的图片全部下载到本程序根目录 #!/usr/bin/env python #! -*- coding: utf-8 -*- import urllib,urllib2 import re #返回网页源代码 def getHtml(url): html = urllib2.urlopen(url) srcCode = html.read() return srcCode def getImg(

C#加载网页中的图片

需求:在winform程序中加载网页中的验证码 1.打开网页,获取到网页中img的src属性,得到的是图片的base64编码字符串: string base64string= webBrowser1.Document.All["yzm_img"].GetAttribute("src"); 2.将字符串转换为图片: byte[] b = Convert.FromBase64String(base64string); MemoryStream ms = new Memo

如何在HTML中实现图片的滚动效果

<MARQUEE onmouseover=stop() onmouseout=start() scrollAmount=3 loop=infinite deplay="0"><IMG src="第一张图片地址" ><IMG src="第二张图片地址"></MARQUEE>注释:1) scrollAmount.它表示速度,值越大速度越快.2) 加入onmouseover=stop() onmouseo

爬取网页中的图片到本地

library(rvest) library(downloader) url <- 'http://www.nipic.com/show/15419595.html' web <- read_html(url) link <- web %>% html_nodes("img") %>% html_attr("src") for(i in 1:length(link)){ download(link[i],paste("D://

Chrome浏览器无法将网页中的图片保存到本地的问题

今天在浏览网页时看到一张图片不错,想保存下来,在图片上点击右键>图片另存为,结果试了好多次都没有反应. 环境: Windows 7操作系统 Chrome 版本 41.0.2272.76 m (64-bit) 原因: 后来发现是这个安全警告框的原因,点击运行以后一下子弹出好多个文件保存对话框,之前试了好多次都没有反应,现在全都弹出来了.