本文实例讲述了jQuery实现的放大镜效果。分享给大家供大家参考,具体如下:
zoom.css:
* { padd : 0;保证金: 0;}李{列表式-类型:无;}.缩放{ margin: 50px相对位置:}.zoomMiddle {边框: 1px实心# CCC宽度: 300像素;高度: 300像素保证金-底部: 3px相对位置:}.zoomMiddle img { width : 300 pxh three : 300 px }。掩模{宽度: 100像素高度: 100像素;背景# abcdefopacity:0.4绝对位置:左: 0;top : 0;显示器:无;}.zoomSmall{ -overflow:隐藏;宽度: 302 px高度: 54px}。zoomSmall span { float : left height : 52px线高: 52px宽度: 10px文本对齐:中心;border: 1px固体# ccccccursor :指针;}.zoomSmall跨度。禁用{ cursor :默认值;背景# ccc}。wrappsmallimg { float : left height : 54 px宽度: 232像素;/*背景: # f00*/position:相对;飞越:隐藏;}.wrapsmallimg ul { width : 348 px;/*背景: # f00*/position:绝对值;左: 0;top : 0;}.wrapSmallImg ul li {左侧浮动:宽度: 50px高度: 50pxborder: 2px固体# cccmargin : 0 2px _ display :内联;光标:指针;}.李。当前{边框: 2px }纯橙色;}.wrapsmallimg ul Li img { width : 50px;高度: 50px}.中联重科{宽度: 350像素高度: 350像素;border: 1px固体# ccc绝对位置:top : 0;左侧: 320像素飞越:隐藏;display:none}。中联重科img {宽度: 600px高度:600 px绝对位置:左: 0;top : 0;}zoom.html:
!doctype html html lang=' en ' hearta charset=' UTF-8 '标题放大镜/titlelink rel='样式表href=' zoom。CSS/head mdy输入类型=' text ' name=' id=' div class=' zoom ' div class=' zoomMiddle ' img src=' http 33601。jpg ' alt=' div class=' mask '/div/div class=' zoomSmall ' span class=' left disable '/span div class=' wrappsmall img ' ul Li class=' current ' img src=' http 33601。使用jpeg文件交换格式存储的编码图像文件扩展名
$(function(){ var smolimgli=$(').wrappsmolimg ul Li’);var小imglitlength=小imgli。size();var smallimgligwidth=smallimgli。out width(true);var smallImgUl=$(' .wrapsmallimg ul’);var left Btn=$(' span。左');var right Btn=$(' span。右’);var now=0;var zoomMiddleDiv=$(' .zoomMiddle’);smallImgLi.mouseover()函数(){ $(这个).addClass('current ').兄弟姐妹()。removeClass(“”当前');var THisrC=$(this).儿童(' img ').attr(' src ');$('.zoomMiddle img ').attr('src ',thisSRc);$('."中联重科"。attr('src ',thisSRc);});rightBtn.click(function(){ //当现在=2的时候,我们不希望再让他滚动了左转Btn。移除类(' disable ');if(now=smallImgLiLength-4){ $(this).添加CLaSS(' disable ');now=smallImgLiLength-4;} else { nowsmallimgul。animate({ ' left ' :-now * smallimgligwidth },300);} });左转Btn。单击(function(){ if(now==0){ now=0;} else { now-;smallimgul。animate({ ' left ' : '=' smallimgligwidth ' },300);} });zoomMiddleDiv.mousemove(函数(e){ $(').面具')。show();$('.中联重科')。show();zoommiddledioffset=zoommiddlediv。offset();var x=e . pagex-zoommiddledioffset。左-$(' .面具')。width()/2;var y=e . pagey-zoommiddioffset。top-$(' .面具')。高度()/2;if(x=0){ x=0;} else if(x=zoommiddlediv。width()-$(').面具')。width()){ x=zoommiddlediv。width()-$(' .面具')。宽度();} if(y=0){ y=0;} else if(y=zoommiddlediv。高度()-$(').面具')。height()){ y=zoommiddlediv。高度()-美元(' .面具')。高度();} var percent x=x/(zoommiddlediv。width()-$(').面具')。width());var百分比y=y/(zoommiddlediv。高度()-$(').面具')。高度());$('."中联重科"。CSS({ left :-percentage x *(600-$(')).中联重科')。width()),top:-percentageY*(600-$(').中联重科')。height())});$("输入")。val(百分比值','百分比值')$('。面具')。css({ 'left':x 'px ',' top ' :y ' px ' });});zoomMiddleDiv.mouseout(函数(){ $(')。面具')。hide();$('.中联重科')。hide();});});效果图如下:
更多关于jQuery相关内容感兴趣的读者可查看本站专题: 《jQuery常用插件及用法总结》 、 《jquery中Ajax用法总结》 、 《jQuery表格(table)操作技巧汇总》 、 《jQuery拖拽特效与技巧总结》 、 《jQuery扩展技巧总结》 、 《jQuery常见经典特效汇总》 、 《jQuery动画与特效用法总结》 及《jquery选择器用法总结》
希望本文所述对大家jQuery程序设计有所帮助。