Follow these steps to set up a vertical news listing:
<ul id="news-carousel"> <li> <img src="images/thumbs/Switzerland.png" alt="Switzerland"/> <div class="info"> <h4>Switzerland</h4> <p>Switzerland, officially the Swiss Confederation, is a federal republic consisting of 26 cantons, with Bern as the seat of the federal authorities</p> </div> </li> <li> <img src="images/thumbs/CostaRica.png" alt="Costa Rica"/> <div class="info"> <h4>Costa Rica</h4> <p>Costa Rica, officially the Republic of Costa Rica, is a country in Central America, bordered by Nicaragua to the north, Panama to the south, the Pacific Ocean to the west and south and the Caribbean Sea to the east.</p> </div> </li> ... </ul>
I've created 12 items in total on my list, each with this same structure. Keep in mind that each item in the carousel must be of the same width and height.
styles.css
file and add a few lines of CSS to get each news item styled the way we'd like, with the image on the left and the headline and excerpt on the right:#news-carousel li { overflow:hidden;zoom:1;list-style-type:none; } #news-carousel li img { float:left; } #news-carousel li .info { margin-left:210px; } #news-carousel h4 { margin:0;padding:0; } #news-carousel p { margin:0;padding:0;font-size:14px; }
Feel free to add some additional CSS to style the list to suit your own taste. If you open the page in a browser, at this point, you can expect to see something similar to the following screenshot:
<head>
section of the document, and the jCarousel plugin script at the bottom of the document, between jQuery and our own scripts.js
file. scripts.js
file. We'll write our document ready statement, select our news ticker, and call the jcarousel()
method, just like we did in the previous example.$(document).ready(function(){ $('#news-carousel').jcarousel(); });
jcarousel()
method to adjust our carousel to work the way that we'd like. First, it should be vertical rather than horizontal, so pass true
as a value for the vertical
key:$('#news-carousel').jcarousel({
vertical:true
});
$('#news-carousel').jcarousel({
vertical:true,
scroll:1
});
$('#news-carousel').jcarousel({
vertical:true,
scroll:1,
wrap:'circular'
});
$('#news-carousel').jcarousel({
vertical:true,
scroll:1,
wrap:'circular',
auto: 3
});
$('#news-carousel').jcarousel({
vertical:true,
scroll:1,
wrap:'circular',
auto: 3,
animation: 600
});
styles.css
file and we'll get started by adjusting the necessary widths and heights as follows:.jcarousel-skin-tango .jcarousel-item { width:475px;height:150px; } .jcarousel-skin-tango .jcarousel-clip-vertical { width:475px;height:470px; } .jcarousel-skin-tango .jcarousel-container-vertical { height:470px;width:475px; }
We've set the size of an individual item to 475 pixels wide by 150 pixels tall. Then the size of the container and clip container are adjusted to show three items. Just as a reminder—since each item in our carousel is 150 pixels tall and there are 10 pixels of space between items, we can calculate the height of the container as follows:
150 + 10 + 150 + 10 + 150 = 470px
We're using heights instead of widths for our calculations since our carousel is now vertical rather than horizontal.
.jcarousel-skin-tango .jcarousel-container { -moz-border-radius: 5px;-webkit-border-radius:5px;border-radius:5px;border-color:#CB4B16;background:#f9d4c5; }
.jcarousel-skin-tango .jcarousel-prev-vertical, .jcarousel-skin-tango .jcarousel-next-vertical { left:0;right:0;width:auto; } .jcarousel-skin-tango .jcarousel-prev-vertical { top:0;background:#cb4b16 url(images/arrows.png) 50% 0 no-repeat; } .jcarousel-skin-tango .jcarousel-prev-vertical:hover, .jcarousel-skin-tango .jcarousel-prev-vertical:focus { background-color:#e6581d;background-position:50% 0; } .jcarousel-skin-tango .jcarousel-next-vertical { background:#cb4b16 url(images/arrows.png) 50% -32px no-repeat;bottom:0; } .jcarousel-skin-tango .jcarousel-next-vertical:hover, .jcarousel-skin-tango .jcarousel-next-vertical:focus { background-color:#e6581d;background-position:50% -32px; }
Now, if you refresh the page in the browser, you'll see that the carousel is re-designed a bit with a different color scheme and appearance:
Moving your mouse over the top or bottom bar will lighten the color a bit, and clicking a bar will advance the carousel in that direction by one item.
What just happened?
In this case, we used the jCarousel plugin to create a vertical news ticker. Our news ticker automatically advances one item every three seconds. We slowed down the animation to make for a smoother reading experience for our site visitors. We also saw how we can customize the tango skin's CSS to customize the color scheme and appearance of the carousel to fit our site's design. Next up, we'll take a look at how we can add some external controls to the carousel.
Have a go hero — design your own carousel
Now that you've seen how to customize the appearance and behavior of the jCarousel plugin, design your own carousel. It could be horizontal or vertical, contain text, images, or a combination of both. Experiment with the settings that the jCarousel plugin makes available to you — you'll find them all listed out and explained in the plugin's documentation.
3.22.51.241