[英]Using Highmaps, how can I use jQuery fadeIn/fadeOut to fade the data while keeping the map visible?
I'm using jQuery fadeIn and fadeOut to provide a smooth transition when switching between two datasets. 我正在使用jQuery fadeIn和fadeOut在两个数据集之间切换时提供平滑的过渡。 Here's the working map:
这是工作图:
https://jsfiddle.net/MossTheTree/h5njdqLf/7/ https://jsfiddle.net/MossTheTree/h5njdqLf/7/
Here's where I fade the container: 这是我淡化容器的位置:
$('#setdataPop').click(function() {
$("#container").fadeOut(500, function() { resetMap(pop); $("#container").fadeIn(500); });
});
This is OK, but I'd like to keep the base map fully visible while fading between the datasets. 可以,但是我希望在数据集之间逐渐消失时保持底图完全可见。 I've considered adding an empty map in a div stacked below as a dummy, but that solution seems a bit clunky.
我曾考虑过在下面堆叠的div中添加一个空白地图作为虚拟对象,但是该解决方案似乎有些笨拙。 I'd appreciate any ideas.
我将不胜感激。
This piece of code takes all the points from the map which have a value and fades them out to white: 这段代码从地图上获取所有具有值的点,然后将它们淡化为白色:
var points = AccessMap.series[0].points,
iterations = 30,
iterationInterval = 20;
points.forEach(function(p) {
if (!p.isNull) {
var rgb = p.color.split(',').map((s) => Number(s.replace(/\D/g, ''))), // convert from string to an array of numbers: [r, g, b]
steps = rgb.map((c) => Math.round((255 - c) / iterations)); // used to increment above values at each iteration
// launch animation
for (var i = 0; i < iterations; i++) {
setTimeout(function(_i, _rgb, _steps) {
if (p.graphic) {
// compute value for fill
var fill = 'rgb(' + _rgb.map(function(c, j) {
var val = c + _steps[j] * (_i + 1);
return val > 255 ? 255 : val;
}).join(',') + ')';
// step may not be precise - make sure that final color is always white
if (_i + 1 === iterations) {
fill = 'white'
}
p.graphic.attr({
fill: fill
});
}
}, i * iterationInterval, i, rgb.slice(), steps.slice());
}
}
});
Live working example: https://jsfiddle.net/kkulig/kupyu65w/ 实时工作示例: https : //jsfiddle.net/kkulig/kupyu65w/
It uses Highcharts Element.attr()
function for setting colors ( http://api.highcharts.com/class-reference/Highcharts.SVGElement#attr ) 它使用Highcharts
Element.attr()
函数设置颜色( http://api.highcharts.com/class-reference/Highcharts.SVGElement#attr )
Fade in function can be created analogically. 淡入功能可以类似地创建。 Just make sure that all the points are white initially.
只需确保所有点一开始都是白色的。
jQuery fadeOut
function is not a solution here because it decreases elements opacity to 0 and in this case the background underneath the point is visible (grayish color). jQuery
fadeOut
函数在这里不是解决方案,因为它将元素的不透明度降低为0,在这种情况下,该点下方的背景是可见的(灰色)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.