简体   繁体   English

在显示动画的同时显示动画并隐藏

[英]To show while animate and animate and hide

Working on an assignment on hover of an image, i have to rotate the image then once image rotation is complete i have to animate another object and then on mouse out rotate the initial image in its original position and then the second object should be animated toward it's initial position and then hide. 在图像悬停上进行分配时,我必须旋转图像,然后一旦图像旋转完成,我就必须为另一个对象设置动画,然后在鼠标移出时将初始图像旋转到其原始位置,然后将第二个对象动画化为它是初始位置,然后隐藏。

Every thing is done but the only problem is while animating to showing object and on mouse out hiding object. 一切都做完了,但是唯一的问题是动画显示对象并在鼠标上隐藏对象。

Working DEMO here. 在这里工作的演示

Used javascript is 使用的JavaScript是

function rotate(degree,el,direction) {
          var interval = null,
          counter = 0;
          interval = setInterval(function(){
            if (direction == "anti_clockwise" ? counter >= degree : counter <= degree) {
              console.log(counter);
              el.css({
                MozTransform: 'rotate(-' + counter + 'deg)',
                WebkitTransform: 'rotate(' + counter + 'deg)',
                transform: 'rotate(' + counter + 'deg)'
              });
              if(direction == "anti_clockwise"){
                counter = counter - 1;
              }else if(direction == "clockwise"){
                counter = counter + 1;
              }
            }
            if (counter == degree && direction == "anti_clockwise") {
              clearInterval(interval);
              $("#prodShareIconDetails ul").animate({"left":"39px"},"slow");
            }
            if (counter == degree && direction == "clockwise") {
              clearInterval(interval);
              $("#prodShareIconDetails ul").animate({"left":"200px"},"slow", function(){

              });
            }
          }, 10);
      }
      $("#prodShareIcon").mouseover(function() {
        rotate(-39,$(this),"anti_clockwise");
      }).mouseout(function() {
        console.log(1);
        rotate(39,$(this),"clockwise");
      });

Can someone help me to understand where i am doing wrong? 有人可以帮助我了解我在哪里做错了吗?

Initially element with id prodShareIconDetails should be hidden and then show on hover. 最初ID为prodShareIconDetails的元素应该被隐藏,然后在悬停时显示。

This is not exactly a trivial problem. 这不是一个简单的问题。 My guess is that on hover you want the icon to rotate, upon completion of that animation, the bar starts to extend outward. 我的猜测是,悬停时您希望图标旋转,动画完成后,栏会开始向外延伸。 Whenever the mouse leaves, the whole process unwinds in the same order. 每当鼠标离开时,整个过程都会以相同的顺序展开。 Currently it's very glitchy if you leave early or mid animation, sometimes ending up in a totally broken state. 当前,如果您离开动画的早期或中期是非常小故障的,有时最终会处于完全损坏的状态。

If I was you I would separate your animations into distinct functions. 如果我是你,我会将动画分成不同的功能。 1) rotate 2) extend, 3) unrotate, 4) retract. 1)旋转2)伸展,3)松开,4)缩回。 Next you string them together by callbacks so that when one completes it calls the other, but using CSS transitions it's a little tougher since it's event based. 接下来,您通过回调将它们串在一起,以便在一个回调完成时调用另一个回调,但是使用CSS过渡会更加困难,因为它基于事件。 The jQuery transit plugin is perfect for making that easy. jQuery transport插件非常适合于简化这一过程。 When rotate is complete, it calls extend. 旋转完成后,它将调用extend。 When the mouseout occurs, it halts all animations, and, depending on how far it got, retracts and unwinds. 发生鼠标移出时,它会暂停所有动画,并视其移动的距离而缩回和展开。

Regarding showing the bar, you actually want the bar visible (so the user can see it extend). 关于显示条,您实际上希望条可见(以便用户可以看到它扩展)。 To accomplish this, put the bar inside another div which will act as a "window" of sorts with overflow: hidden; position: relative; 为此,将栏放在另一个div中,该div充当带有overflow: hidden; position: relative;某种“窗口” overflow: hidden; position: relative; overflow: hidden; position: relative; . Then position the bar position: absolute; 然后将杆的position: absolute; so that when it shouldn't be visible it's positioned outside the visible space of our "window". 因此,当它不可见时,它位于“窗口”的可见空间之外。 This "window" and "track" method is common for doing sliding animations. 这种“窗口”和“跟踪”方法通常用于制作滑动动画。 One example is Hulu , check out the "popular shows" and other sliders midway down the page. 一个例子是Hulu ,查看页面下方的“热门节目”和其他滑块。

Fixed DEMO IS HERE 固定的演示在这里

TRICK WRAPPER WIDTH 0 AND MOVE THE ELEMENT IN RIGHT 欺骗包裹者宽度0,并向右移动元素

#prodShareIconDetails{
width: 0px;
position: absolute;
top: -16px;
right: 10px;
z-index:10;
overflow:hidden;
}

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

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