Convert Global Code to jQuery Function
I'm new to jQuery but pretty familiar with JavaScript. I would like to convert the code below to a function that can be used like "$("#member-feedback li").rotateElements()". I've looked at some examples, but I'm not sure where to start. Thanks for your help.
- var els = [];
- var idx = 0;
- var num = 0;
- function rotateElements() {
- els.eq(idx).hide();
- idx++;
- if(idx >= num) { idx = 0; }
- els.eq(idx).fadeIn('slow');
- }
- $(function() {
- els = $('#member-feedback li');
- num = els.length;
- idx = Math.floor(Math.random() * num)
- els.eq(idx).show();
- setInterval('rotateElements()', 7000);
- });