简体   繁体   English

进出jQuery的动画窗口

[英]Animate window in and out jQuery

I created a toggle switch in jQuery. 我在jQuery中创建了一个切换开关。 If you click on a marker, a sidebar is sliding inside the screen, and when you click the same marker, it slides back. 如果单击标记,则侧栏会在屏幕内滑动,而单击同一标记时,它会向后滑动。 But, I have multiple markers on my screen, and if you click another marker, the animation continues to slide inside, so the sidebar is getting bigger. 但是,我的屏幕上有多个标记,如果单击另一个标记,动画将继续在内部滑动,因此侧边栏会越来越大。 What I want is that when you click any marker, that the sidebar is staying the same size, but I cannot achieve it with what I tried myself. 我想要的是,当您单击任何标记时,边栏保持不变,但是我自己尝试无法实现。 The code: 编码:

   google.maps.event.addListener(marker, 'click', function() {
                infowindow.open(map,marker);

                if(windowOpen)
                {

                    sidebar.animate({ 
                        width: "-=300px" 
                    }, 500, function()
                    {
                        console.log('complete');
                    });


                 windowOpen = false;

                }
                else
                {
                    sidebar.animate({ 
                        width: "+=300px" 
                    }, 500, function()
                    {



                    });

                    windowOpen = true;
                }



              });

Can anyone point me in the right direction? 谁能指出我正确的方向?

Many thanks! 非常感谢!

Looks like you haven't defined windowOpen outside of the eventHandler. 看起来您尚未在eventHandler之外定义windowOpen Thus, on every click windowOpen is undefined leading to your else code being executed. 因此,在每次单击时windowOpen都是未定义的,导致您的else代码被执行。 Try this: 尝试这个:

var windowOpen = false;

google.maps.event.addListener(marker, 'click', function() {
  // your code
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM