简体   繁体   English

使用Highmaps,如何在保持地图可见的情况下使用jQuery fadeIn / fadeOut淡化数据?

[英]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.

相关问题 如何使用jQuery(或CSS)淡入/淡出文本? - How can I fadeIn/fadeOut of text using jQuery (or CSS)? 如何限制jQuery中fadeIn()和fadeOut()函数的执行次数? - how can i limit the number of executions of fadeIn () and fadeOut () functions in jQuery? 我如何从一个jQuery触发fadeIn()fadeOut() <div> 元件 - How can I trigger jQuery fadeIn() fadeOut() from a <div> element 使用 Highmaps,为什么我的 jQuery 淡入淡出中的回调会在淡入淡出完成之前发生? - With Highmaps, why is the callback in my jQuery fadein happening prior to the fade completing? jQuery的淡出和淡入如何不闪烁 - jquery fadeout and fadein how to not flashing 如何在jQuery中切换淡入/淡出效果? - How do I switch the fadeIn/fadeOut effect on an image in jQuery? JQuery中的元件fadeOut()和fadeIn()时的replaceWith() - replaceWith() while elements fadeOut() and fadeIn() in JQuery 如何使用相同的按钮来实现fadeOut()和fadeIn()? - How could I use the same button to achieve the fadeOut() and fadeIn()? 在淡出效果完成后执行淡入淡出的JQuery淡出功能如何使用? - How exactly works this use of the JQuery fadeout function that perform the fadein after the fadeout effect is completed? 我如何将fadeOut 或fadeIn 动画添加到我的JS 函数中 - How can i add fadeOut or fadeIn animation to my JS function
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM