0

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>. 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.

4
  • 1
    GET andres321r.byethost15.com/carousel/jquery-1.10.2.min.map 404 (Not Found) Commented Oct 1, 2013 at 21:15
  • Can you recreate your problem in a fiddle ? Commented Oct 1, 2013 at 21:15
  • 3
    @RUJordan That is irrelevant, it's the jquery map so you can decompress the code and get the variable names instead of a,b,c... Commented Oct 1, 2013 at 21:16
  • 2
    You don't need the jQuery mapping file for it to work. Plus, that error appears only when you have the dev tools open Commented Oct 1, 2013 at 21:16

2 Answers 2

4

This is a pure CSS issue. You need only to add position: relative; to your li, so you can effect the left property in your script.

.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. Ciao!

Sign up to request clarification or add additional context in comments.

3 Comments

Yes that worked! Thanks, Now I would need to read more into how to make it a functional carousel lol.
Happy to help. Additionally, there is always the jQuery Cycle plugin: jquery.malsup.com/cycle. Also, I have a small Github example of a cycler function that might help you: github.com/kunalbhat/cycler
Yeah I know there's a lot of plugins out there but I want to start learning how to create my own lol. I'll have a look at yours to see if I learn anything. Thanks again.
0

Add position: relative to your .carousel-inner li.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.