国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 語言 > JavaScript > 正文

jquery 圖片縮放拖動的簡單實例

2024-05-06 15:59:03
字體:
來源:轉載
供稿:網友
本篇文章只要是對jquery 圖片縮放拖動的簡單實例進行了介紹,需要的朋友可以過來參考下,希望對大家有所幫助

一、不使用jquery,簡單的縮放:

復制代碼 代碼如下:


<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<TITLE>onMouseWheel</TITLE>
<SCRIPT>
var count = 10;
function Picture()
{
count = Counting(count);
Resize(count);
return false;
}
function Counting(count){
if (event.wheelDelta >= 120)
count++;
else if (event.wheelDelta <= -120)
count--;
return count;
}
function Resize(count){
oImage.style.zoom = count + '0%';
oCounter.innerText = count + '0%';
}
</SCRIPT>
</HEAD>
<BODY>
<div align=center>
<span>Size =
<span>100%</span></span>
<img src="images/aaa.gif" onmousewheel="return Picture();" >
</div>
</BODY>
</HTML>


一、使用jquery,實現縮放和拖動:

復制代碼 代碼如下:


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <title></title>
    <style type="text/css">
        #imgBox
        {
            width: 200px;
            height: 200px;
            background: red;
            overflow: hidden;
            margin: auto;
            position: relative;
        }
        #imgMain
        {
            position: relative;
            top: -200px;
        }
    </style>
    <script src="js/jquery-1.2.6.js" type="text/javascript"></script>
    <script type="text/javascript" language="javascript">
        $(function () {
            var event;
            if ($.browser.mozilla) {
                event = "DOMMouseScroll";
            }
            else {
                event = "mousewheel";
            }
            $("#divBlock").bind(event,
        function (e) {
            var evt = window.event || e;
            var newWidth;
            var newHeight;
            var newLeft;
            var newTop;
            var overHeight = $("#divBlock").height();
            if (evt.detail > 0 || evt.wheelDelta < 0) {
                newWidth = $("#imgMain").width() - 20;
                newHeight = $("#imgMain").height() - 20;
                newLeft = $("#imgMain").position().left + 10;
                newTop = $("#imgMain").position().top + 10 - overHeight;
            }
            else {
                newWidth = $("#imgMain").width() + 20;
                newHeight = $("#imgMain").height() + 20;
                newLeft = $("#imgMain").position().left - 10;
                newTop = $("#imgMain").position().top - 10 - overHeight;
            }

            $("#imgMain").css({ left: newLeft + "px", top: newTop + "px" });

            $("#imgMain").width(newWidth);
            $("#imgMain").height(newHeight);
        }
        );

            $("#divBlock").bind("mousedown", function (e) {
                var xo = e.pageX;
                var yo = e.pageY;
                var imgLeft = $("#imgMain").position().left;
                var imgTop = $("#imgMain").position().top;
                var overHeight = $("#divBlock").height();
                $("#divBlock").bind("mousemove", function (e) {

                    window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
                    var x = e.pageX;
                    var y = e.pageY;

                    var bX = $("#imgBox").offset().left;
                    var bY = $("#imgBox").offset().top;

                    $("#imgMain").css("left", x - bX - (xo - bX) + imgLeft);
                    $("#imgMain").css("top", y - bY - (yo - bY) - overHeight + imgTop);
                });

            });

            $("#divBlock").bind("mouseup mouseout", function () {
                $("#divBlock").unbind("mousemove");
            });

        });
    </script>
</head>
<body>
    <div>
        <div>
        </div>
        <img src="test.jpg" />
    </div>
</body>
</html>

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表

圖片精選

主站蜘蛛池模板: 昌宁县| 清河县| 长阳| 师宗县| 阳信县| 五常市| 茶陵县| 林甸县| 南丰县| 景德镇市| 九龙县| 师宗县| 沭阳县| 连云港市| 德钦县| 宁津县| 崇明县| 南通市| 随州市| 游戏| 泌阳县| 新源县| 黄浦区| 郧西县| 丘北县| 兴仁县| 屏山县| 汕头市| 平乐县| 宁明县| 垫江县| 项城市| 巴塘县| 松溪县| 新干县| 梁平县| 渝北区| 惠来县| 武安市| 济源市| 庆元县|