d3地图浮框

本文介绍如何利用d3.js库,在中国地图上实现鼠标悬停时显示省份浮框的功能。浮框内容自定义,位置动态跟随鼠标,提供详细的地图交互体验。
摘要由CSDN通过智能技术生成

d3地图浮框。中国地图鼠标滑动到每一个省的时候,都能显示出一个省的浮框。浮框的内容可以设置,位置跟随鼠标移动。

    function getFloatTag(node) {
   
      var $floatTagContainer = $(node);

      var FloatTagFactory = function() {
   
        var mouseToFloatTag = {
    x: 20, y: 20 };
        var setContent = function() {
   };
        //var canMove = true; // if move when it's show. true, false;
        var loc;
        var node;
        var container;
        var mousePannel;
        var timeOut;
        var globalScale = 1;
        //set floatTag location, warning: the html content must be set before call this func,
        // because jqNode's width and height depend on it's content;
        var _changeLoc = function(l) {
   
          //m is mouse location, example: {x: 10, y: 20}
          var m = l || loc;
          var x = m.x / globalScale;
          var y = m.y / globalScale;
          var floatTagWidth = node.outerWidth
            ? node.outerWidth()
            : node.width();
          var floatTagHeight = node.outerHeight
            ? node.outerHeight()
            : node.height();
          var mousex = mouseToFloatTag.x / globalScale;
          var mousey = mouseToFloatTag.y / globalScale;

          if (floatTagWidth + x + 2 * mousex <= $(container).width()) {
   
            x 
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值