Js实现图片缩放上下左右移动效果
2013-04-26 16:44
1141 查看
1、JS—Code:
var rate = 0.2;
var pp = document.getElementById("viewArea");
var vv = document.getElementById("picview");
var ie = document.all;
var nn6 = document.getElementById && !document.all;
//是否拖拽(默认否)
var isdrag = false;
var y, x; var st, sl;
//鼠标移动 function moveMouse(e) {
if (isdrag) {
var mouseX = nn6 ? e.clientX : event.clientX;
var mouseY = nn6 ? e.clientY : event.clientY;
vv.scrollTop = st + (y - mouseY);
vv.scrollLeft = sl + (x - mouseX);
return false;
}
}
//拖拽
function initDrag(e) {
var oDragHandle = nn6 ? e.target : event.srcElement;
isdrag = true;
x = nn6 ? e.clientX : event.clientX;
y = nn6 ? e.clientY : event.clientY;
st = vv.scrollTop;
sl = vv.scrollLeft;
document.onmousemove = moveMouse;
return false;
}
pp.onmousedown = initDrag;
pp.onmouseup = new Function("isdrag=false");
//放大
function bigit() {
pp.style.height = pp.height * (1 + rate) + "px";
pp.style.width = pp.width * (1 + rate) + "px";
}
//缩小 function smallit() {
pp.style.height = pp.height * (1 - rate) + "px";
pp.style.width = pp.width * (1 - rate) + "px"; }
//原始大小 function realsize() {
var newImg = new Image();
newImg.src = pp.src;
pp.style.height = newImg.height + "px";
pp.style.width = newImg.width + "px"; }
//通过箭头移动图片 function clickMove(s) {
if (s == "up") {
vv.scrollTop = vv.scrollTop - 100;
} else if (s == "down") {
vv.scrollTop = vv.scrollTop + 100;
} else if (s == "left") {
vv.scrollLeft = vv.scrollLeft - 100;
} else if (s == "right") {
vv.scrollLeft = vv.scrollLeft + 100;
} }
//交换图片 function changeImage(path) {
pp.src = path;
pp.style.width = "600px";
vv.scrollTop = 0;
vv.scrollLeft = 0;
}
2、ASPX页面源码:
<div id="contral">
<table>
<tr>
<td>
<img src="images/DragPic/down.png" width="27" height="14" onclick="clickMove('down')"
title="DOWN" />
</td>
<td>
<img src="images/DragPic/up_icon.png" width="27" height="14" onclick="clickMove('up')"
title="UP" />
</td>
<td>
<img src="images/DragPic/left.png" width="14" height="27" onclick="clickMove('left')"
title="LEFT" />
</td>
<td>
<img src="images/DragPic/right_icon.png" width="14" height="27" onclick="clickMove('right')"
title="RIGHT" />
</td>
<td>
<img src="images/DragPic/+_icon.png" width="25" height="25" onclick="bigit();" title="ZOOM IN" />
<td>
<img src="images/DragPic/-_icon.png" width="25" height="5" onclick="smallit();" title="ZOOM OUT" />
</td>
</tr>
</table>
</div>
<div class="pubbox kqzl">
<div class="pubbox kqzl2" id="picview">
<img width="240" height="449" alt="Moving" name="viewArea"
id="viewArea" /><br />
<br />
</div>
</div>
<script src="Scripts/PicDrag.js" type="text/javascript"></script>
3、效果图:
var rate = 0.2;
var pp = document.getElementById("viewArea");
var vv = document.getElementById("picview");
var ie = document.all;
var nn6 = document.getElementById && !document.all;
//是否拖拽(默认否)
var isdrag = false;
var y, x; var st, sl;
//鼠标移动 function moveMouse(e) {
if (isdrag) {
var mouseX = nn6 ? e.clientX : event.clientX;
var mouseY = nn6 ? e.clientY : event.clientY;
vv.scrollTop = st + (y - mouseY);
vv.scrollLeft = sl + (x - mouseX);
return false;
}
}
//拖拽
function initDrag(e) {
var oDragHandle = nn6 ? e.target : event.srcElement;
isdrag = true;
x = nn6 ? e.clientX : event.clientX;
y = nn6 ? e.clientY : event.clientY;
st = vv.scrollTop;
sl = vv.scrollLeft;
document.onmousemove = moveMouse;
return false;
}
pp.onmousedown = initDrag;
pp.onmouseup = new Function("isdrag=false");
//放大
function bigit() {
pp.style.height = pp.height * (1 + rate) + "px";
pp.style.width = pp.width * (1 + rate) + "px";
}
//缩小 function smallit() {
pp.style.height = pp.height * (1 - rate) + "px";
pp.style.width = pp.width * (1 - rate) + "px"; }
//原始大小 function realsize() {
var newImg = new Image();
newImg.src = pp.src;
pp.style.height = newImg.height + "px";
pp.style.width = newImg.width + "px"; }
//通过箭头移动图片 function clickMove(s) {
if (s == "up") {
vv.scrollTop = vv.scrollTop - 100;
} else if (s == "down") {
vv.scrollTop = vv.scrollTop + 100;
} else if (s == "left") {
vv.scrollLeft = vv.scrollLeft - 100;
} else if (s == "right") {
vv.scrollLeft = vv.scrollLeft + 100;
} }
//交换图片 function changeImage(path) {
pp.src = path;
pp.style.width = "600px";
vv.scrollTop = 0;
vv.scrollLeft = 0;
}
2、ASPX页面源码:
<div id="contral">
<table>
<tr>
<td>
<img src="images/DragPic/down.png" width="27" height="14" onclick="clickMove('down')"
title="DOWN" />
</td>
<td>
<img src="images/DragPic/up_icon.png" width="27" height="14" onclick="clickMove('up')"
title="UP" />
</td>
<td>
<img src="images/DragPic/left.png" width="14" height="27" onclick="clickMove('left')"
title="LEFT" />
</td>
<td>
<img src="images/DragPic/right_icon.png" width="14" height="27" onclick="clickMove('right')"
title="RIGHT" />
</td>
<td>
<img src="images/DragPic/+_icon.png" width="25" height="25" onclick="bigit();" title="ZOOM IN" />
<td>
<img src="images/DragPic/-_icon.png" width="25" height="5" onclick="smallit();" title="ZOOM OUT" />
</td>
</tr>
</table>
</div>
<div class="pubbox kqzl">
<div class="pubbox kqzl2" id="picview">
<img width="240" height="449" alt="Moving" name="viewArea"
id="viewArea" /><br />
<br />
</div>
</div>
<script src="Scripts/PicDrag.js" type="text/javascript"></script>
3、效果图:
相关文章推荐
- JS实现图片滚动(无缝、平滑、上下左右滚动)效果
- 简单实现谷歌地图的图片缩放,移动效果的JS
- js实现键盘的上下左右控制图片移动
- js实现简单的动画(4个按钮控制图片上下左右移动)
- js实现鼠标左右移动,图片也跟着移动效果
- 图片的左右移动,js动画效果实现代码
- js实现方块上下左右移动效果
- 图片的左右移动,js动画效果实现代码
- js实现上下左右图片轮播效果(三)
- JS实现元素上下左右移动效果
- JS—实现元素上下左右移动
- jquery插件jquery.LightBox.js实现点击放大图片并左右点击切换效果(附demo源码下载)
- css3 来实现图片在指定容器内等比例缩放,并控制中上下左右居中
- js实现图片左右移动轮播
- JS实现鼠标移动到缩略图显示大图的图片放大效果
- 用JS实现键盘左右键控制图片移动
- 为ScrolloView加手势实现上下左右移动效果
- js实现鼠标移动到图片产生遮罩效果