javascript - Fill list up to 10 items -
I have up to 10 items & lt; Ul & gt;
Seeing a way to fill the list. If the list does not contain 10 in HTML, then I want to repeat the item itself. For example:
& lt; Ul id = "carousel" & gt; & Lt; Li & gt; & Lt; A href = "#" & gt; 1 & lt; / A & gt; & Lt; / Li & gt; & Lt; Li & gt; & Lt; A href = "#" & gt; 2 & lt; / A & gt; & Lt; / Li & gt; & Lt; Li & gt; & Lt; A href = "#" & gt; 3 & lt; / A & gt; & Lt; / Li & gt; & Lt; Li & gt; & Lt; A href = "#" & gt; 4 & lt; / A & gt; & Lt; / Li & gt; & Lt; / Ul & gt;
I tried to do it myself, but it is not working properly that I want it:
max_slides = 10; Slide_holder = $ ('#branded'); All_slides = $ ('# Carousel Li'); Number_of_slides = all_slides.length; Number_of_slides_to_add = max_slides - number_of_slides; If (number_of_slides & lt; max_slides) {slides_to_add = $ ('# carousel li: lieutenant (' + number_of_slide_to_and + ')'). Clone (); Slides_holder.append (slides_to_add); } // $ ('#branded'). BeginSocial ();
It should be:
& lt; Ul id = "carousel" & gt; & Lt; Li & gt; & Lt; A href = "#" & gt; 1 & lt; / A & gt; & Lt; / Li & gt; & Lt; Li & gt; & Lt; A href = "#" & gt; 2 & lt; / A & gt; & Lt; / Li & gt; & Lt; Li & gt; & Lt; A href = "#" & gt; 3 & lt; / A & gt; & Lt; / Li & gt; & Lt; Li & gt; & Lt; A href = "#" & gt; 4 & lt; / A & gt; & Lt; / Li & gt; & Lt; Li & gt; & Lt; A href = "#" & gt; 1 & lt; / A & gt; & Lt; / Li & gt; & Lt; Li & gt; & Lt; A href = "#" & gt; 2 & lt; / A & gt; & Lt; / Li & gt; & Lt; Li & gt; & Lt; A href = "#" & gt; 3 & lt; / A & gt; & Lt; / Li & gt; & Lt; Li & gt; & Lt; A href = "#" & gt; 4 & lt; / A & gt; & Lt; / Li & gt; & Lt; Li & gt; & Lt; A href = "#" & gt; 1 & lt; / A & gt; & Lt; / Li & gt; & Lt; Li & gt; & Lt; A href = "#" & gt; 2 & lt; / A & gt; & Lt; / Li & gt; & Lt; / Ul & gt;
The objects must repeat itself. It works only when there are 5 items or more ... The reason for this is: I am using a special carousel plugin that always has 10 items always needed. If this does not happen, then it starts to show.
Thanks for any help.
I have to take it:
var $ container = $ ( '# Carousel'); Var $ Original = $ Container Children ('li'); Var Total hair = $ original.length; While (Total kids & lt; 10) {$ container.append ($ original.clone ()); Total child = $ container. Child ('li'). Length; } $ Container.children ('li: gt (9)'). Remove ();
Note that : gt
is based on 0.
Comments
Post a Comment