简体   繁体   English

使用animate()在javascript中使用上一个/下一个按钮滑动图像

[英]Sliding images with Previous/Next buttons in javascript using animate()

I have a slideshow of 4 banners with Prev and Next button. 我有一个带有上一页和下一页按钮的4条横幅的幻灯片显示。 It works fine with the Prev button but not the Next button.My problem is Once I press the Next button, the images move not properly. 它可以与“上一个”按钮一起使用,但不能与“下一个”按钮一起使用。我的问题是一旦按下“下一个”按钮,图像将无法正确移动。

This is the result I need.=> The next image on the right slides from right to left when clicking Next button.Now it slides but sometimes some images slides back to the right. 这是我需要的结果。=>单击下一步按钮时,右侧的下一个图像从右向左滑动。现在它滑动了,但有时某些图像向右滑动。

Please help.Thank you 请帮忙。谢谢

<http://jsfiddle.net/pktono/sr5nv6k9>

So, there was couple of issues to fix: 因此,有几个问题需要解决:

1- animation time was overriding the css command. 1-动画时间覆盖了css命令。 To fix that, you should use setTimeout function where your aftermath code should reside inside of it. 要解决此问题,您应使用setTimeout函数,将后果代码放在其中。

2- When you navigate to right, you set the previous banner left property to -650px. 2-当导航到右侧时,将上一个横幅left属性设置为-650px。 If you decide to navigate to the left at this moment, you have a wrong left property which ruin the rules. 如果您决定此时导航到左侧,则可能是left属性错误,从而破坏了规则。 The same thing can happen when you are navigating to left and want to switch to right. 当您导航到左侧并想切换到右侧时,可能会发生同样的事情。 To fix this, you should change left property of the current banner to the right value before animating it. 要解决此问题,您应在将其显示动画之前将当前标题的left属性更改为right值。

See the working example here 这里查看工作示例

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

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