简体   繁体   English

为什么我的点击功能在jquery中不起作用?

[英]Why doesn't my click function work in jquery?

I wan to create a simple carousel that holds an image title and text. 我想创建一个简单的轮播,其中包含图片标题和文本。 When I click the "next" span, it should display the next two <li> . 当我单击“下一个”跨度时,它将显示接下来的两个<li> But nothing happens when I do so. 但是,当我这样做时,什么也没有发生。

<script type="text/javascript">
    $(document).ready(function() {
        $('#right').click(function() {
            $('li').animate({
                left: '-600px'
            }, 500);
        });
    });
</script>

Fiddle 小提琴

See this example . 请参阅此示例

This is a pure CSS issue. 这是一个纯CSS问题。 You need only to add position: relative; 您只需要添加position: relative; to your li , so you can effect the left property in your script. 您的li ,因此您可以影响脚本中的left属性。

.carousel-inner li {
  display: inline;
  float: left;
  margin: 20px;
  border: 1px solid #999;
  padding: 25px;
  border-radius: 20px;
  position: relative; // Add this so setting a left position will work
}

Simply try adding that in Chrome Inspector and you'll see it works. 只需尝试在Chrome Inspector中添加它,即可看到它的工作原理。 Ciao! 再见!

添加position: relative对于您的.carousel-inner li

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

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