Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/454.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript RaphaelJS:移除悬停和移动元素时的闪烁_Javascript_Svg_Raphael - Fatal编程技术网

Javascript RaphaelJS:移除悬停和移动元素时的闪烁

Javascript RaphaelJS:移除悬停和移动元素时的闪烁,javascript,svg,raphael,Javascript,Svg,Raphael,我对Raphael JS和SVG都很陌生。目前我正在使用SVG和Raphael的地图功能 我有一个悬停效果的问题,它抵消了你悬停在10px上的给定元素。但是,如果您将鼠标缓慢移动到元素中,则hoverIn和hoverOut会发生多次,导致闪烁 我想我可以通过克隆这些国家来解决这个问题,并让它们在盘旋时保持隐藏和静止。我可以这么做,因为地图上有数百个形状 方法是什么?我该怎么办?如果我理解正确,当您将鼠标悬停在元素上时,该元素会移动,从而导致悬停事件。您希望鼠标缓慢移动时发生什么情况?它移动一次,

我对Raphael JS和SVG都很陌生。目前我正在使用SVG和Raphael的地图功能

我有一个悬停效果的问题,它抵消了你悬停在10px上的给定元素。但是,如果您将鼠标缓慢移动到元素中,则hoverIn和hoverOut会发生多次,导致闪烁

我想我可以通过克隆这些国家来解决这个问题,并让它们在盘旋时保持隐藏和静止。我可以这么做,因为地图上有数百个形状


方法是什么?我该怎么办?

如果我理解正确,当您将鼠标悬停在元素上时,该元素会移动,从而导致悬停事件。您希望鼠标缓慢移动时发生什么情况?它移动一次,一直移动直到鼠标进入

您需要在元素上设置一个变量,以显示它何时被移位10px。然后您可以执行类似(伪代码)的操作

hoverIn() { 
    if (isShifted) {
        inWhenShifted = true  
    } else {
        // offset element
        isShifted = true
    } 

hoverOut() {
    if (isShifted) { 
         if (inWhenShifted) {
             // put element back
             isShifted = false
             inWhenShifted = false
         } else {
             // do nothing?, this is the case where the hoverOut fired 
             // because we moved the element
         }
    } else {
        // do nothing?, this is the case where we hoverOut again after shifting
        // the element back
    }
}