图片添加热点(封装方法)

<!DOCTYPE html>

<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8" />
    <title></title>
    <style type="text/css">
        * {
            margin: 0px;
            padding: 0px;
        }

        #zhezhao {
            position: fixed;
            top: 0px;
            left: 0px;
            width: 100%;
            height: 100%;
            background-color: black;
            opacity: 0.7;
            z-index: 100;
            display: none;
        }

        #img_box {
            position: fixed;
            top: 1%;
            left: 10%;
            width: 80%;
            height: 98%;
            z-index: 101;
            display: none;
        }

        #close {
            position: absolute;
            top: 10px;
            right: 10px;
            width: 40px;
        }

        #append {
            display: block;
            margin: 0 auto;
        }
    </style>
    <script type="text/javascript">
        window.onload = function () {
            //动态创建map与子级area
            create("myMap", "myMap1", "myMap2", "img", "53,413,71,970,0,998,0,376", "1577,148,1576,1101,1235,976,1240,396");

            function create(id, idarea1, idarea2, idimg, c1, c2) {
                var newmap = document.createElement("map");
                newmap.setAttribute("id", id);
                newmap.setAttribute("name", id);
                document.getElementById("box").appendChild(newmap);
                var newarea = document.createElement("area");
                newarea.setAttribute("id", idarea1);
                newarea.setAttribute("shape", "poly");
                newarea.setAttribute("coords", c1);
                newarea.setAttribute("onclick", "areaclick('" + idimg + "');");
                document.getElementById("myMap").appendChild(newarea);
                var newarea1 = document.createElement("area");
                newarea1.setAttribute("id", idarea2);
                newarea1.setAttribute("shape", "poly"); //620, 70, 620, 430, 490, 380, 490, 160
                newarea1.setAttribute("coords", c2);
                newarea1.setAttribute("onclick", "areaclick('" + idimg + "');");
                document.getElementById("myMap").appendChild(newarea1);
            }

            document.getElementById("close").onclick = function () {
                document.getElementById("append").setAttribute("src", "");
                document.getElementById("zhezhao").style.display = "none";
                document.getElementById("img_box").style.display = "none";
            }
        }

        function areaclick(idimg) {
            document.getElementById("zhezhao").style.display = "block";
            document.getElementById("img_box").style.display = "block";
            var h = document.getElementById("img_box").offsetHeight;
            var w = document.getElementById("img_box").offsetWidth;
            document.getElementById("append").style.maxWidth = w + "px";
            document.getElementById("append").style.maxHeight = h + "px";
            var src = document.getElementById(idimg).src;
            document.getElementById("append").setAttribute("src", src);
            var h1 = document.getElementById("append").style.height;
            document.getElementById("append").style.marginTop = (h - h1) / 2;
        }
    </script>
</head>
<body>
    <div id="box">
        <img src="images/back3.jpg" border="0" usemap="#myMap" alt="Planets" id="img" />
    </div>

    <div id="zhezhao"></div>
    <div id="img_box">
        <img id="close" src="images/wtg.png" />
        <img id="append" src="" />
    </div>

</body>
</html>

 

转载于:https://www.cnblogs.com/123lucy/p/6738407.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值