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