简体   繁体   English

在jQuery中对div位置进行动画处理

[英]Animate div position in jQuery

I'm learning to use jQuery, I'm not an expert programmer. 我正在学习使用jQuery,但我不是专业的程序员。 I'm using animate effect to build a horizontal navigation for the loop of WP installation (no scrolls). 我正在使用animate效果为WP安装循环构建水平导航(无滚动)。 I animate 960px in x axis the loop with a “Next Page” button and go to start going (to 0px x position) with a “start” button. 我使用“下一页”按钮在x轴上为960px动画,然后使用“开始”按钮开始(到0px x位置)开始循环。 The container of this has an overflow:hidden CSS property in order to hide the posts outside the container. 为了将帖子隐藏在容器外部,此容器具有一个overflow:hidden CSS属性。

Please see a live example . 请看一个现场例子

I don't know how to stop the slide effect when reaching the end of the loop div. 当到达循环div的末尾时,我不知道如何停止滑动效果。 Maybe with a conditional statement, but I don't know to approach this. 也许带有条件语句,但是我不知道该如何处理。

This is the script: 这是脚本:

<script type="text/javascript">
$(document).ready(function(){
$(".left-slide").click(function(){
  $("#slide-container").animate({
    left:"-=960"
  }, 1500 );
});
$(".right-slide").click(function(){
  $("#slide-container").animate({
    left:"0"
  }, 1500 );
});
});
</script>

Would something like this work? 这样的事情行吗?

if($("#slide-container").css('left') > -($("#slide-container").width()))
{
}

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

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