jquery實現(xiàn)的放大鏡效果示例
本文實例講述了jquery實現(xiàn)的放大鏡效果。分享給大家供大家參考,具體如下:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>商品詳情</title>
<link rel="stylesheet" href="../css/shoplistxq.css" rel="external nofollow" >
</head>
<body>
<div class="main box">
<div class="img">
<img src="../img/shoplist/TB1lO6XJpXXXXc_XFXXLhc5_XXX_054423.jpg" alt="">
<div class="bri"></div>
<div class="big"></div>
</div>
<div class="content">
<h3>2件衛(wèi)衣男士長袖t恤加厚打底衫加絨秋衣保,<br>
暖上衣男裝冬季衣服潮
買一送一!2件僅需89!加絨不加價!</h3>
<div>價格¥ 168.00</div>
<div>尺碼</div>
<div>顏色</div>
<div>數(shù)量</div>
<div>加入購物車</div>
</div>
</div>
</body>
</html>
<script src="../js/jquery-1.11.3.js"></script>
<script src="../js/shoplistxq.js"></script>
shoplistxq.css:
*{
margin:0;
padding:0;
font-family: "微軟雅黑";
}
ul li{
list-style: none;
}
a{
text-decoration: none;
color: #666;
}
/*主體寬度*/
.main {
margin:0 auto;
width: 1210px;
}
.box{
margin-top: 50px;
}
.box::after{
content: ".";
height:0;
overflow: hidden;
visibility: hidden;
clear: both;
}
.img{
width: 400px;
height: 400px;
border: 1px solid #666666;
position: relative;
float: left;
}
.img img{
width: 100%;
height: 100%;
}
.bri{
position: absolute;
width: 100px;
height: 100px;
left:0;
top:0;
background: rgb(233, 118, 118);
opacity: .5;
cursor: crosshair;
}
.big{
width:100%;
height: 100%;
position: absolute;
background: url("../img/shoplist/TB1lO6XJpXXXXc_XFXXLhc5_XXX_054423.jpg");
left:401px;
top:0;
background-size: 100%;
display:none;
}
.content{
float: right;
}
shoplistxq.js:
$(function() {
$(".img").mousemove(function (e) {
$(".bri").css({
"left": e.pageX - $(this).offset().left - $(".bri").width() / 2,
"top": e.pageY - $(this).offset().top - $(".bri").height() / 2
})
if (parseFloat($(".bri").css("left")) < 0){
$(".bri").css("left","0");
// console.log("kk");
} else if (parseFloat($(".bri").css("left")) >= parseFloat($(this).width() - $(".bri").width())){
// alert("kk");
$(".bri").css("left",$(this).width() - $(".bri").width());
}
if (parseFloat($(".bri").css("top")) < 0) {
$(".bri").css("top", "0");
} else if (parseFloat($(".bri").css("top")) >= parseFloat($(this).height() - $(".bri").height())) {
// alert("kk");
$(".bri").css("top", $(this).height() - $(".bri").height());
}
console.log($(".img").css("background"))
// 放大倍數(shù)
let num = 4;
let left = -num * parseFloat($(".bri").css("left"));
let top = -num * parseFloat($(".bri").css("top"));
// console.log($(".bri").css("left"))
$(".big").css({
"background-size": num*100+"%",
"background-position":left+"px " +top+"px",
"display":"block"
// "background": $(".img").css("background")
});
})
})
$(".img").mouseout(function (e) {
$(".big").css({
"display": "none"
// "background": $(".img").css("background")
});
})
更多關(guān)于jQuery相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《jQuery常用插件及用法總結(jié)》、《jQuery表格(table)操作技巧匯總》、《jQuery拖拽特效與技巧總結(jié)》、《jQuery擴展技巧總結(jié)》、《jQuery常見經(jīng)典特效匯總》及《jquery選擇器用法總結(jié)》
希望本文所述對大家jQuery程序設(shè)計有所幫助。
相關(guān)文章
JavaScript的jQuery庫插件的簡要開發(fā)指南
這篇文章主要介紹了JavaScript的jQuery庫插件的簡要開發(fā)指南,分為基于選擇器的插件和不基于選擇器的插件兩種情況,需要的朋友可以參考下2015-08-08
深入理解jQuery中l(wèi)ive與bind方法的區(qū)別
本篇文章主要是對jQuery中l(wèi)ive與bind方法的區(qū)別進行了詳細的分析介紹,需要的朋友可以過來參考下,希望對大家有所幫助2013-12-12
jquery 實現(xiàn)input輸入什么div圖層顯示什么
這篇文章主要介紹jquery實現(xiàn)input輸入什么div圖層顯示什么的具體過程,需要的朋友可以參考下2014-06-06
jQuery購物車插件jsorder用法(支持后臺處理程序直接轉(zhuǎn)換成DataTable處理)
這篇文章主要介紹了jQuery購物車插件jsorder用法,結(jié)合實例形式分析了購物車jsorder插件基于ajax與后臺交互的相關(guān)技巧,需要的朋友可以參考下2016-06-06

