Advertisement
Guest User

Untitled

a guest
Apr 29th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. $(document).ready(function(){
  2.  
  3. var i = 0 ;
  4. var colors = ["red","blue","green"];
  5.  
  6. showColors(colors);
  7. $("#addcolor").click(function(){
  8. var x = $(".color").val();
  9. colors.push(x);
  10.  
  11. showColors(colors);
  12. $("#slider").css({
  13. "background-color": $(".slides1").css("background-color")
  14.  
  15. });
  16.  
  17. });
  18.  
  19.  
  20. $(document).on("click",".deletebtn",function(event){
  21. event.preventDefault();
  22. var id = $(this).data("id");
  23. showColors(colors);
  24.  
  25. })
  26.  
  27. function showColors(colors){
  28. var output = "";
  29. for(var i = 0; i< colors.length; i++){
  30. output += "<div class='dom slides"+i+"' data-color='"+colors[i]+"' style='background-color:" + colors[i] + "'><button data-id='"+i+"'class='deletebtn'>x</button></div>";
  31. }
  32. $("#colorcontainer").html(output);
  33.  
  34. }
  35.  
  36. var slideIndex = 1 ;
  37. $("#next").click(function(){
  38.  
  39. showDivs(slideIndex+=1);
  40.  
  41.  
  42. });
  43. $("#previous").click(function(){
  44.  
  45. showDivs(slideIndex-=1);
  46. });
  47. function showDivs (n){
  48.  
  49. var slidesCount = $(".dom").length;
  50. if(n > slidesCount){
  51. slideIndex = 0;
  52. }
  53. if(n < 1){
  54.  
  55. slideIndex = slidesCount.length-1;
  56.  
  57. }
  58. var color = $(".slides"+slideIndex+"").css("background-color");
  59. console.log(color);
  60. $("#slider").css({
  61. "background-color": color
  62.  
  63.  
  64.  
  65. })
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73. }
  74.  
  75.  
  76. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement