javascript - Add dots to fadein slider -


i'dont know javascript enough add dots navigation script, need use script.

can add dot navigation script ?

(function() {     var quotes = $(".quotes");     var quoteindex = -1;     function shownextquote() {         ++quoteindex;         quotes.eq(quoteindex % quotes.length)             .fadein(600)             .delay(4000)             .fadeout(600, shownextquote);     }     shownextquote(); })(); 

you can give position: relative; slider container , dots container position: absolute; place dots wherever want.

i dots, equal length of .quotes. they're spans actual dot , has class="dot", normal dot has black color , active 1 white. can use images instead while active 1 has different src. .active added corresponding dot , removed previous.

var quotes = $(".quotes"); var quoteindex = -1;  (var = 0; < quotes.length; i++)     $('#dots').append($('<span/>').addclass('dot').text("."));  function shownextquote() {     ++quoteindex;     $('.dot.active').removeclass('active');     $('.dot').eq(quoteindex % quotes.length).addclass('active');     quotes.eq(quoteindex % quotes.length)         .fadein(600)         .delay(4000)         .fadeout(600, shownextquote); } shownextquote(); 

added little css transition make transition smooth.

.dot {     display: inline-block;     font-size: 48px;     font-weight: bold;     color: black;     margin-left: 10px;     transition: color 600ms ease-in-out; } .dot.active {     color: white; } 

jsfiddle demo

edit:

to make dots clickable, give them cursor: pointer; clickable , give them click listeners:

$('.dot').on('click', function() {     $('.dot.active').removeclass('active');     clicked = true;     $(this).addclass('active');     quoteindex = $(this).index()-1;     $('.quotes').hide();     $('.quotes').eq($(this).index()).show(); }); 

updated jsfiddle


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -