jQuery實(shí)現(xiàn)的放大鏡效果示例
本文實(shí)例講述了jQuery實(shí)現(xiàn)的放大鏡效果。分享給大家供大家參考,具體如下:
zoom.css:
*{ padding: 0; margin: 0; } li{ list-style-type: none; } .zoom{ margin: 50px; position: relative; } .zoomMiddle{ border: 1px solid #ccc; width: 300px; height: 300px; margin-bottom: 3px; position: relative; } .zoomMiddle img{ width: 300px; height: 300px; } .mask{ width: 100px; height: 100px; background: #abcdef; opacity:0.4; position: absolute; left: 0; top: 0; display: none; } .zoomSmall{ -overflow: hidden; width: 302px; height: 54px; } .zoomSmall span{ float: left; height: 52px; line-height: 52px; width: 10px; text-align: center; border: 1px solid #ccc; cursor: pointer; } .zoomSmall span.disable{ cursor: default; background: #ccc; } .wrapSmallImg{ float: left; height: 54px; width: 232px; /*background: #f00;*/ position: relative; overflow: hidden; } .wrapSmallImg ul{ width: 348px; /*background: #f00;*/ position: absolute; left: 0; top: 0; } .wrapSmallImg ul li{ float: left; width: 50px; height: 50px; border: 2px solid #ccc; margin: 0 2px; _display: inline; cursor: pointer; } .wrapSmallImg ul li.current{ border: 2px solid orange; } .wrapSmallImg ul li img{ width: 50px; height: 50px; } .zoomLarge{ width: 350px; height: 350px; border: 1px solid #ccc; position: absolute; top: 0; left: 320px; overflow: hidden; display:none; } .zoomLarge img{ width: 600px; height:600px; position: absolute; left: 0; top: 0; }
zoom.html:
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <title>放大鏡</title> <link rel="stylesheet" href="zoom.css"> </head> <body> <input type="text" name="" id=""> <div class="zoom"> <div class="zoomMiddle"> <img src="1.jpg" alt=""> <div class="mask"></div> </div> <div class="zoomSmall"> <span class="left disable"><</span> <div class="wrapSmallImg"> <ul> <li class="current"><img src="1.jpg" alt=""></li> <li><img src="2.jpg" alt=""></li> <li><img src="3.jpg" alt=""></li> <li><img src="4.jpg" alt=""></li> <li><img src="5.jpg" alt=""></li> <li><img src="6.jpg" alt=""></li> </ul> </div> <span class="right">></span> </div> <div class="zoomLarge"><img src="1.jpg" alt=""></div> </div> <script src="jquery.js"></script> <script src="zoom.js"></script> </body> </html>
zoom.js:
$(function(){ var smallImgLi = $('.wrapSmallImg ul li'); var smallImgLiLength = smallImgLi.size(); var smallImgLiWidth = smallImgLi.outerWidth(true); var smallImgUl = $('.wrapSmallImg ul'); var leftBtn = $('span.left'); var rightBtn = $('span.right'); var now = 0; var zoomMiddleDiv = $('.zoomMiddle'); smallImgLi.mouseover(function(){ $(this).addClass('current').siblings().removeClass('current'); var thisSrc = $(this).children('img').attr('src'); $('.zoomMiddle img').attr('src',thisSrc); $('.zoomLarge img').attr('src',thisSrc); }); rightBtn.click(function(){ //當(dāng)now=2的時(shí)候,我們不希望再讓他滾動(dòng)了 leftBtn.removeClass('disable'); if(now>=smallImgLiLength-4){ $(this).addClass('disable'); now = smallImgLiLength-4; }else{ now++; smallImgUl.animate({'left':-now*smallImgLiWidth},300); } }); leftBtn.click(function(){ if(now==0){ now=0; }else{ now--; smallImgUl.animate({'left':'+='+smallImgLiWidth},300); } }); zoomMiddleDiv.mousemove(function(e){ $('.mask').show(); $('.zoomLarge').show(); zoomMiddleDivOffset = zoomMiddleDiv.offset(); var x = e.pageX - zoomMiddleDivOffset.left - $('.mask').width()/2; var y = e.pageY - zoomMiddleDivOffset.top - $('.mask').height()/2; if(x<=0){ x=0; }else if(x>=zoomMiddleDiv.width()-$('.mask').width()){ x = zoomMiddleDiv.width()-$('.mask').width(); } if(y<=0){ y=0; }else if(y>=zoomMiddleDiv.height()-$('.mask').height()){ y = zoomMiddleDiv.height()-$('.mask').height(); } var percentageX = x/(zoomMiddleDiv.width()-$('.mask').width()); var percentageY = y/(zoomMiddleDiv.height()-$('.mask').height()); $('.zoomLarge img').css({ left:-percentageX*(600-$('.zoomLarge').width()), top:-percentageY*(600-$('.zoomLarge').height()) }); $('input').val(percentageX+','+percentageY) $('.mask').css({ 'left':x+'px', 'top':y+'px' }); }); zoomMiddleDiv.mouseout(function(){ $('.mask').hide(); $('.zoomLarge').hide(); }); });
效果圖如下:
更多關(guān)于jQuery相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《jQuery常用插件及用法總結(jié)》、《jquery中Ajax用法總結(jié)》、《jQuery表格(table)操作技巧匯總》、《jQuery拖拽特效與技巧總結(jié)》、《jQuery擴(kuò)展技巧總結(jié)》、《jQuery常見(jiàn)經(jīng)典特效匯總》、《jQuery動(dòng)畫(huà)與特效用法總結(jié)》及《jquery選擇器用法總結(jié)》
希望本文所述對(duì)大家jQuery程序設(shè)計(jì)有所幫助。
- jquery圖片放大鏡效果
- jquery實(shí)現(xiàn)放大鏡簡(jiǎn)潔代碼(推薦)
- 基于jquery編寫(xiě)的放大鏡插件
- jQuery實(shí)現(xiàn)圖片局部放大鏡效果
- jQuery實(shí)現(xiàn)放大鏡效果實(shí)例代碼
- 基于jQuery仿淘寶產(chǎn)品圖片放大鏡特效
- 基于jQuery實(shí)現(xiàn)放大鏡特效
- jquery實(shí)現(xiàn)圖片放大鏡功能
- 基于jQuery仿淘寶產(chǎn)品圖片放大鏡代碼分享
- 基于jquery實(shí)現(xiàn)放大鏡效果
- 使用jquery實(shí)現(xiàn)放大鏡效果
- jquery放大鏡效果超漂亮噢
- jquery圖片放大鏡功能的實(shí)例代碼
- 基于jquery的放大鏡效果
- 實(shí)現(xiàn)jquery放大鏡的兩種方法
相關(guān)文章
jQuery制作簡(jiǎn)潔的多級(jí)聯(lián)動(dòng)Select下拉框
省市多級(jí)聯(lián)動(dòng)的select下拉框有很多種實(shí)現(xiàn)方式,度娘上隨便一搜就一大堆,今天我們來(lái)討論的這款特效,代碼卻很簡(jiǎn)潔,兼容性也非常棒,推薦給大家。2014-12-12jQuery文字橫向滾動(dòng)效果的實(shí)現(xiàn)代碼
下面小編就為大家?guī)?lái)一篇jQuery文字橫向滾動(dòng)效果的實(shí)現(xiàn)代碼。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2016-05-05jQuery EasyUI API 中文文檔 - Form表單
jQuery EasyUI API 中文文檔 - Form表單,使用jQuery EasyUI的朋友可以參考下。2011-10-10jquery 圖片截取工具jquery.imagecropper.js
工作需要參考網(wǎng)上的一些代碼做了個(gè)圖片截取工具,最后干脆封裝成一個(gè)jquery的插件。2010-04-04修改好的jquery滾動(dòng)字幕效果實(shí)現(xiàn)代碼
修改好的jquery滾動(dòng)字幕效果,需要的朋友可以參考下。2011-06-06JQuery 學(xué)習(xí)筆記01 JQuery初接觸
jQuery是一個(gè)Javascript庫(kù),用于簡(jiǎn)化Web相關(guān)的Javascript開(kāi)發(fā)2010-05-05jquery trigger偽造a標(biāo)簽的click事件取代window.open方法
這篇文章主要介紹了使用jquery trigger 觸發(fā)a標(biāo)簽的click事件取代window.open方法,需要的朋友可以參考下2014-06-06jquery.validate提示錯(cuò)誤信息位置方法
這篇文章主要介紹了jquery.validate提示錯(cuò)誤信息位置方法,實(shí)例分析了jquery.validate實(shí)現(xiàn)提示錯(cuò)誤信息位置的相關(guān)技巧,需要的朋友可以參考下2016-01-01