Pannellum:实例之自定义热点信息

使用 添加hotSpots参数并对其设置,可以对全景图片添加热点.

效果图:
在这里插入图片描述

代码:

<!DOCTYPE html>
<html lang="ch">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="author"content=“KaiSarH,huankai7@163.com”>
    <title>Custom controls</title>
    <link rel="stylesheet" href="pannellum.css"/>
    <script type="text/javascript" src="pannellum.js"></script>

    <style>
        #panorama {
            width: 600px;
            height: 400px;
        }
        .custom-hotspot {
            height: 50px;
            width: 50px;
            background: #f00;
        }
        div.custom-tooltip span {
            visibility: hidden;
            position: absolute;
            border-radius: 3px;
            background-color: #fff;
            color: #000;
            text-align: center;
            max-width: 200px;
            padding: 5px 10px;
            margin-left: -220px;
            cursor: default;
        }
        div.custom-tooltip:hover span{
            visibility: visible;
        }
        div.custom-tooltip:hover span:after {
            content: '';
            position: absolute;
            width: 0;
            height: 0;
            border-width: 10px;
            border-style: solid;
            border-color: #fff transparent transparent transparent;
            bottom: -20px;
            left: -10px;
            margin: 0 50%;
        }
    </style>
</head>
<body>

<div id="panorama"></div>

<script>
    // Create viewer
    viewer = pannellum.viewer('panorama', {
        "type": "equirectangular",
            "panorama": "test/test.jpg",
            "hotSpots": [
            {
                "pitch": 14.1,
                "yaw": 1.5,
                "cssClass": "custom-hotspot",
                "createTooltipFunc": hotspot,
                "createTooltipArgs": "Baltimore Museum of Art"
            },
            {
                "pitch": -9.4,
                "yaw": 222.6,
                "cssClass": "custom-hotspot",
                "createTooltipFunc": hotspot,
                "createTooltipArgs": "Art Museum Drive"
            },
            {
                "pitch": -0.9,
                "yaw": 144.4,
                "cssClass": "custom-hotspot",
                "createTooltipFunc": hotspot,
                "createTooltipArgs": "North Charles Street"
            }
        ]
    });

    // Hot spot creation function
    function hotspot(hotSpotDiv, args) {
        hotSpotDiv.classList.add('custom-tooltip');
        var span = document.createElement('span');
        span.innerHTML = args;
        hotSpotDiv.appendChild(span);
        span.style.width = span.scrollWidth - 20 + 'px';
        span.style.marginLeft = -(span.scrollWidth - hotSpotDiv.offsetWidth) / 2 + 'px';
        span.style.marginTop = -span.scrollHeight - 12 + 'px';
    }
</script>

</body>
</html>

总结:

classList.add增加class
appendChild向节点的子节点列表的末尾添加新的子节点
createElement() 方法通过指定名称创建一个元素

评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

KaiSarH

如果觉得文章不错,可以支持下~

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值