The last thing developers need today is another jQuery and/or CSS3 based content slider or carousel. I think the problems with these types of modules have been well documented.
About a year ago, however, I wrote a step-by-step tutorial for Issue #203 of Web Designer Mag that involved creating a “news content switcher”. I’ve been meaning to revisit, tweak, and release the code for that here and so I finally got around to it.
This module, like the original in the magazine, is responsive and uses CSS3 for animation. What I find is more practical about this one (compared to the usual carousels and whatnot) is the fact that there’s no mystery as to what’s coming next; all the news items are clearly on display.
The content that shows in the preview (the image and description) is really incidental. That is, it’s not necessary to the readability and/or scannability of the module’s content, so I think it’s much more usable than other content sliders and switchers. In this way it’s a little more like a tab switcher, which has visible and clear options, rather than mystery items sliding in by surprise.
It’s not a jQuery plugin, it’s just a plug-and-play script with simple editable markup. This is because, other than speed and auto-rotating, I couldn’t find many significant “options” to include. Those two options are very easy to change in the code by reading the code comments.
Also, if you want different colors, the styles in the CSS file can be changed easily to accommodate any context.
I’m sure this has a few weaknesses (like accessibility; the clickable news headlines are not using anchors — is that bad?), so I’m glad to look at suggestions for improvements. You can view it on GitHub or use the links below to download and view a demo.
You are right about this being better usability than most “mystery” sliders. The other big advantage comes from being more persuasive. when changing the slider from one feature to the next the eye moves along a shorter path than in most sliders where the eye must move outside the picture and down to a little number for the slide. in your version the person viewing is absorbing and remembering in short term memory the headline for the new article instead of keeping their short term memory fixed on an arbitrary slide number 4 they need to click. If you want your readers looking at your content what you have is good. if you are satisfied with readers spending the time they’ve planned for your site to be spent looking at numbers and counting slide rotations, then a traditional jquery slider should be just fine.
I would possibly recommend adding a next and previous button because sometimes users want to use case: click, see picture, click, see picture, click see picture. quickly or at a speed of their choosing this should be doable without having to look at the mouse pointer and focus on moving the pointer to the next location. A fixed position next and previous button allows the user to position their mouse over the next button and then focus visually on the photo or headline while clicking quickly. If you satisfied with users having to stop looking at the content to track the movement of the mouse to the correct slide then you don’t need the next and previous buttons.
Also there’s a slight confusion over when do we switch slides. in my opinion simply mousing over the text with a hover intent delay should be enough to switch slides since it indicates the user is focused on a particular slide earlier and easier then clicking. One related problem that always bothers me with this sort of slideshow is that you have to click twice to get to a news article. first you click on the tab to get the slide photo and page link, then you have to look for the mouse, move the mouse to the correct link for the page featured in the slide, then click on the page link. A better plan might be to let hover select the slide when you hover over a title and clicking the title on the left goes directly to the article. That would be less clicking and maybe more intuitive if done right.
That’s a good point about the hovering. I personally prefer clicking though, so I’ll probably keep it as is, as it’s simple enough to use.
I would love to hide some of the lists and use a vertical scroller, how can I do that?
The only way would be to add vertical up/down arrows and use JavaScript to scroll it up/down. I can’t think of a simple way to just to a plain vertical scroll bar. It would look ugly and ruin the usability of it.
You can try fiddling with it here:
https://jsbin.com/utaneq/edit?html,css,js,output
I have been trying to get text color in news-headlines change when it is in selected state. How do i go about doing that?
Here you go:
https://jsbin.com/utaneq/85/edit?html,css,js,output
You have to add the following selector to override the color:
The JavaScript will then swap it automatically.
is it possible for the animation to start automatically, rather than having to click to start it?
Wow, you really had me stumped there!
The auto-sliding feature was always working, and it worked on page load. But you were right, for some reason it was only starting after clicking an item. I couldn’t figure it out. So I went back to the code on JS Bin, and I noticed that the older version of the code was using jQuery 1.8.1, while the live demo on this website was using jQuery 1.10.2. So it turns out, for some reason, I had made some changes and then updated the jQuery version and it broke the auto-sliding feature.
I still can’t figure out what was causing the breakage. It seems to have either been the
trigger()
method, theindex()
method, or else one of the jQuery selectors was incorrect. I’m still not sure.I reverted the code and the demo to jQuery 1.8.1 so it should now work as expected. Sorry about that. Let me know if there are any other problems.
I like it! Thank you for sharing.
Do you have any idea how to make the animation stop when cursor is hovering over content? Thinking along the lines of “focus” but cannot seem to get anything to work. Like to stop advancement to next area when mouse/cursor is over content.
That’s actually a really nice idea. Adds to the usability. You can do it quickly by adding the following lines anywhere in the JS file inside the main closure:
I’ll see about adding that to the code base, I think it’s good. Thanks!
Thanks Louis.
I was trying to hard or in other words trying to make it hard with difficult code:)
Very nice code. Going to use this as a “squeeze page” (opt-in page) to showcase a product. Betting it will convert very well.
Wishing you and yours a great week ahead.
Woody
Opps. Does not work for me.
Placed the code into (at very bottom) vertical.news.slider.js. Then tried it right on page and hovering does not stop the scroll.
I do get some errors:
Uncaught ReferenceError: myTimer is not defined vertical.news.slider.js:114
Uncaught ReferenceError: doTimedSwitch is not defined vertical.news.slider.js:118
Not sure where to define myTimer, but do see it at line 17 with a null value.
Keep hacking away ans see what I can come up with.
Woody
I edited my original comment immediately after I posted it, so maybe you read the wrong comment. I originally said to put the code “anywhere” but you actually have to put it inside the big function closure. Notice the following line at the top:
And the following line at the bottom:
Put it above that last line, so it’s inside the closure. Those opening/closing lines prevent naming collisions with other code, so if you put it outside, then the “myTimer” and “doTimedSwitch” objects are not recognized, which explains the errors.
Thank you once again Louis. I should have caught that myself.
First of all, I would like to thank you for this wonderful news slider.
I have a question for you regarding the slider. When the content was too much, it broke the bottom border. Is there a way to make the box’s height auto expand (down) as the content get bigger?
Hi Duy,
Thanks for pointing that out. The reason that was happening is because each of the content elements that hold the photo and text are positioned absolutely in CSS, so they overlap each other. I then would give them a min-height value. But that was not really enough.
So, I fixed it by adding a couple of new lines in the JavaScript. Please download the new version from GitHub and it should work as you want now.
Let me know if there are any problems.
Wonderful ! It’s exactly what I mean. Thank you. I just bought the volume 1 of your book. Hopefully after reading them, I won’t have to ask you any more questions :)
By the way I have another question. When I tried to add google address maps (with the “iframe” code provided by google) to different news-contents, only the top-content shows the map correctly. The other contents show the top half of the map, but they’re not even the correct addresses.
Thank you, I saw your name in the purchase, and was wondering if that was you. :)
I’m not sure about the Google maps thing. Can you send me a demo link that I could see?
Sorry, English is not my native language; maybe I didn’t make it clear enough for you.
So for example, under the
<div class=”news-content top-content”>, I add this:
[googlemaps https://www.google.com/maps/embed?pb=!1m18!1m12!1m3!1d47953.61516558328!2d-105.61265645!3d41.3066675!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x876884f78eda9b79%3A0x8e89c1f7a1c4e593!2sLaramie%2C+WY!5e0!3m2!1sen!2s!4v1406189290990&w=600&h=450%5D
And under the next <div class=”news-content”>, I add this:
<iframe src=”https://www.google.com/maps/embed?pb=!1m18!1m12!1m3!1d196281.64169563106!2d-104.85511145!3d39.764338949999996!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x876b80aa231f17cf%3A0x118ef4f8278a36d6!2sDenver%2C+CO!5e0!3m2!1sen!2s!4v1406189776485″ width=”600″ height=”450″ frameborder=”0″ style=”border:0″><iframe>
The second map will not work correctly in my laptop. If it still doesn’t make sense then I will upload the demo site and send you the link.
It is wonderful thanks for you,
I want to view items by listview control how can do that , I tried but it doesn,t work
This is a great plugin, thanks! It would be even more fantastic if it worked with jQuery 1.10.2 just to keep it running in projects going forward. If you had a fix for this that would fab!
Yes, for sure. I’m going to have to set aside some time to figure out why it’s not working in later versions, and correct it. Thanks for the reminder.
still not working with jQuery 1.10.2 !?! – we are in 2016 now… Do you have a fix?
Hi roux, not sure if you’ll get this reply but I’ve corrected the problem. The news slider now works in all version of jQuery.
I’m building my first wp theme ever. I did tried to add this to wp, but no luck. This is how i’v done.
http://pastebin.com/6ez7DHLJ
Can you take a look and tell me what i am doing wrong ?
Thanks
If it’s a WordPress theme, then you have to make sure the script is inside the correct folder, and you reference it correctly.
For example, you have:
But that’s not correct for a WP theme. It would instead be something like this:
Or whatever the path to your theme directory is. You might have to hard-code it or use a different WP function. Just make sure it points to the right file, and the file exists in that location.
You also need to remove this:
That’s my Google Analytics, and should not appear on your website. (It won’t hurt anything, but it’s loading scripts for nothing, which slows the page down).
Hey, thanks for a reply. I noticed later analytic code which i removed. I tried all the same with default html code and it works. But when instead of html i add php it appears but doesnt work. Also the right side shows all the posts, so as for one i need a proper php code to add. What confuses me is that it has two , selected class and a normal one, so i am not sure how php code for this would look like. Second thing is , that the right side .news-content all posts are shown in streched box. I did try to set a fixed height and to add overflow:hidden but no luck, which brings me back to php code. According to you, the one i added in previous comment is good ?
Kind regards
Html is erased . I meant here about li tags ” What confuses me is that it has two , selected class and a normal one, so i am not sure how php code for this would look like “
I really don’t know. Can you send me the entire WP theme, as a zip file, so I can test it myself? I’ll be glad to debug it for your, but I need the original PHP files, not just an HTML demo, and not just the code.
I used to create a website through WordPress. So, if the client requires a carousel, it won’t be difficult as some plugins are ready to use, and you just have to install it from the control panel. However, right now, I am trying to create a website from scratch, i.e. through pure html, css, PHP, etc., and I find your post very helpful in my learning process. Thank you for this.
Hey,
cool script – thanks for sharing!
Now I wanted to use this with jQuery 1.10.2 but – as mentioned above – it didn’t work. In my opinion elCount is the problem: From V1.9.0 on it is 0 until you activate the first anchor. So I chose .length instead of .index() for counting the children and it worked out.
Maybe this helps improving this script.
Greetings from Germany!
Ah, thanks, I’ll look into it!
Hi Louis, did u find any solution for the latest jQuery version?
I am waiting for your reply.
Best
Use the solution mentioned by the commenter “NC”, above. I don’t really have time to look into it, but it seems pretty simple according to his comment.
Thanks for sharing brother…
I have been trying for a while now to remove the bullets but it’s not going anywhere. pls help?
It’s in the CSS using a pseudo-element. It looks like this:
Just edit that section (or just remove it) to change the bullet style.
plz provide me tutorial for this slider
Hi Louis,
Is it possible to add dynamic content. I have been trying to append a news item and it never picks up the new news-headlines. So if it do an ajax call to pull back a headline (which I can do all this) how would I update the ticker to reflect the new item programmatically?
Figured it out! Put all the variable calls in the custom btn add or function. Drop your script above the btn/function where you add new items. In your original variables set those like the following…
And here is the btn_add which injects each item into the placeholders in the html.
And for the css I remove the padding so my Bootstrap buttons were not affected. And removed the yellow backgrounds…
Before:
After:
Hope this helps someone in the future! Great Script Louis! Going to work nicely for the skip logic in my Natural Language Chat Bot Builder!
Glad it worked out. Thanks for the code tip.
I have a lot of information to display and I want to limit the display to 6 information per page by adding vertical up / down arrows and use JavaScript to scroll it up / down while leaving automatic navigation how I can achieve it?
Hi Louis, I’m trying to use your vertical news jquery plugin with getDatePicker calendar (http://glad.github.io/glDatePicker/#home)
but for my surprise the date of the calendar changes every time the news changes in your plugin. Maybe some kind of common event triggers the change in both plugins. Any clue?
Oh it’s because of the “selected” class in the CSS I think. If you want, change the “selected” class in the CSS and in the JavaScript to something like “newsSelected” in mine, and leave the date plugin the same, and it should work fine like that. It just needs something unique.
If that doesn’t solve the problem, can you post a demo on JS Bin or CodePen or something like that, so I can see an example where the problem occurs? Thanks.
It’s works¡¡¡ thanks a lot, Louis, now i can use your plugin with getDatePicker calendar.
Best regrads¡
Does the slider work properly with Internet Explorer 11? For some reason my News Preview is below my news-headline Links. In other browsers it shows the news preview to the right of the news-headline links. I have not adjusted any of the CSS; however your demo works properly in IE 11. Any ideas why mine shows up at the bottom?
You’re going to have to send me a link so I can look at it, otherwise I can’t help. Thanks.
Sorry I do not have a link as it is an internal site. However after doing some more research; I found out that by removing the <!DOCTYPE> tag it now works in IE 11. Thanks for the help, and I hope this helps out in the future.
Hi John,
You shouldn’t have to remove the doctype tag. That will have other undesirable effects in the long run. Is it possible you could just post an example of the code you’re using (not the whole page) on something like CodePen, then I could take a look at it?
https://codepen.io/jre08/pen/dGBZXM
Hi John,
I’m not sure what you’re seeing in IE11, but it looks like it works fine in IE11 for me. Are you sure you pasted the correct code? Can you take a screenshot of what you see?
hi louis ..
great code congatulations and thank you…
is it possible to make this carousel as a vertical Infinite Scrolling Carousel flowing downwards continously”?
so this way it will not go in a row for not only six tpics but lets say a 100 news topics..
thank advance for your time
oz
I’m sure you can just use 100 items then just use CSS to hide the ones you don’t want to see or something like that. But I’m not really sure because this is a pretty old post now ;)