Js实现图片缩放上下左右移动效果

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" οnclick="clickMove('down')"
                        title="DOWN" />
                </td>
                <td>
                    <img src="images/DragPic/up_icon.png" width="27" height="14" οnclick="clickMove('up')"
                        title="UP" />
                </td>
                <td>
                    <img src="images/DragPic/left.png" width="14" height="27" οnclick="clickMove('left')"
                        title="LEFT" />
                </td>
                <td>
                    <img src="images/DragPic/right_icon.png" width="14" height="27" οnclick="clickMove('right')"
                        title="RIGHT" />
                </td>
                <td>
                    <img src="images/DragPic/+_icon.png" width="25" height="25" οnclick="bigit();" title="ZOOM IN" />
                    <td>
                        <img src="images/DragPic/-_icon.png" width="25" height="5" οnclick="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、效果图:

转载于:https://www.cnblogs.com/dean-Wei/archive/2013/04/26/3045177.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值