效果圖
平原網站制作公司哪家好,找創(chuàng)新互聯(lián)公司!從網頁設計、網站建設、微信開發(fā)、APP開發(fā)、成都響應式網站建設等網站項目制作,到程序開發(fā),運營維護。創(chuàng)新互聯(lián)公司從2013年開始到現(xiàn)在10年的時間,我們擁有了豐富的建站經驗和運維經驗,來保證我們的工作的順利進行。專注于網站建設就選創(chuàng)新互聯(lián)公司。
代碼部分
html內容:
css樣式:
/*
最外層容器id=demo
*/
#container{
display: block;
width: 400px;
height: 400px;
margin: 50px;
position: relative;
border: 1px solid #ccc;
}
/*
原圖容器id=small-Container
*/
#small-container{
position: relative;
z-index: 1;
}
/*
原圖上的圖層id=mark-container
*/
#mark-container{
position: absolute;
display: block;
width: 400px;
height: 400px;
background-color: #FFF;
opacity: 0;
z-index: 2;
cursor: move;
}
/*
原圖上的移動圖層id=float-Container
*/
#float-container{
display: none;
width: 200px;
height: 200px;
position: absolute;
background-color: #F5F5DC;
border: 1px solid #ccc;
filter:alpha(opacity=50);
opacity: 0.5;
}
/*
大圖容器id=big-Container
*/
#big-container{
display: none;
position: absolute;
top: 0;
left: 420px;
width: 460px;
height: 460px;
overflow: hidden;
border: 1px solid #ccc;
z-index: 1;
}
/*
大圖片
*/
#big-container img{
position: absolute;
z-index: 2;
}
script腳本:
$(function(){
var objContainer = $("#container");
var objSmallContainer = $("#small-container");
var objMarkContainer = $("#mark-container");
var objFloatContainer = $("#float-container");
var objBigContainer = $("#big-container");
var objBigImage = $(objBigContainer).children('img');
//鼠標移入事件
$(objMarkContainer).mouseover(function(event) {
$(objFloatContainer).css({
display: 'block'
});
$(objBigContainer).css({
display: 'block'
});
});
//鼠標移出事件
$(objMarkContainer).mouseout(function(event) {
$(objFloatContainer).css({
display: 'none'
});
$(objBigContainer).css({
display: 'none'
});
});
//鼠標移動事件
$(objMarkContainer).mousemove(function(event) {
var _event = event || window.event;
var clientX = _event.clientX;
var clientY = _event.clientY;
var objContainerOffsetLeft = $(objContainer).offset().left;
var objContainerOffsetTop = $(objContainer).offset().top;
var objSmallContainerOffsetLeft = $(objSmallContainer).offset().left;
var objSmallContainerOffsetTop = $(objSmallContainer).offset().top;
var objFloatContainerWidth = $(objFloatContainer).outerWidth();
var objFloatContainerHeight = $(objFloatContainer).outerHeight();
var objMarkContainerWidth = $(objMarkContainer).outerWidth();
var objMarkContainerHeight = $(objMarkContainer).outerHeight();
var objBigContainerWidth = $(objBigContainer).outerWidth();
var objBigContainerHeight = $(objBigContainer).outerHeight();
var objBigImageWidth = $(objBigImage).outerWidth();
var objBigImageHeight = $(objBigImage).outerHeight();
var left = clientX - objContainerOffsetLeft - objSmallContainerOffsetLeft - objFloatContainerWidth / 2;
var top = clientY - objContainerOffsetTop - objSmallContainerOffsetTop - objFloatContainerHeight / 2;
if (left < 0) {
left = 0;
}else if (left > (objMarkContainerWidth - objFloatContainerWidth)) {
left = objMarkContainerWidth - objFloatContainerWidth;
}
if (top < 0) {
top = 0;
}else if (top > (objMarkContainerHeight - objFloatContainerHeight)) {
top = objMarkContainerHeight - objFloatContainerHeight;
}
$(objFloatContainer).css({
left: left + 'px',
top: top + 'px'
});
var percentX = left / (objMarkContainerWidth - objFloatContainerWidth);
var percentY = top / (objMarkContainerHeight - objFloatContainerHeight);
$(objBigImage).css({
left: (-percentX * (objBigImageWidth - objBigContainerWidth)) + 'px',
top: (-percentY * ( objBigImageHeight - objBigContainerHeight)) + 'px'
});
});
});