Advertisement
Guest User

Untitled

a guest
Mar 30th, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.83 KB | None | 0 0
  1. jQuery(document).ready(function($) {
  2. if($('.test')[0]){
  3.  
  4. var circles = $('.testcircle').length,
  5. halfcircles = circles / 2;
  6.  
  7. function colorStrToIntArray(color) {
  8. if (color.length == 4 || color.length == 7) {
  9. color = color.substr(1);
  10. }
  11. if (color.length == 3) {
  12. var r = parseInt(color.substr(0, 1) + color.substr(0, 1), 16),
  13. g = parseInt(color.substr(1, 1) + color.substr(1, 1), 16),
  14. b = parseInt(color.substr(2, 1) + color.substr(2, 1), 16);
  15.  
  16. return [r, g, b];
  17. }
  18. else if (color.length == 6) {
  19. return [
  20. parseInt(color.substr(0, 2), 16),
  21. parseInt(color.substr(2, 2), 16),
  22. parseInt(color.substr(4, 2), 16)
  23. ];
  24. }
  25. return false;
  26. }
  27.  
  28. function calculateSteps(color1, color2, steps) {
  29. var output = [],
  30. start = colorStrToIntArray(color1),
  31. end = colorStrToIntArray(color2);
  32. var calculate = function(start, end, step) {
  33. return start + Math.round((end - start) * (step / (steps / 2)));
  34. };
  35. for ( var i = 0; i < steps; i++ ) {
  36. var color = [0, 0, 0];
  37. color[0] = calculate(start[0], end[0], i);
  38. color[1] = calculate(start[1], end[1], i);
  39. color[2] = calculate(start[2], end[2], i);
  40. output.push(color);
  41. }
  42. return output;
  43. }
  44.  
  45. var colors = calculateSteps("#f29111", "#e60000", halfcircles),
  46. colors2 = calculateSteps("#d20911", "#22637e", halfcircles),
  47. cars = $('.testcircle');
  48. index = 0;
  49.  
  50. $('.testcircle').each(function() {
  51. var $carrot = $("<div>", {"class": "testw6"});
  52. $(this).closest('li').find('.testw5').prepend($carrot);
  53. if (index < halfcircles) {
  54. $(this).css('background-color', 'rgb(' + colors[index][0] + ', ' + colors[index][1] + ', ' + colors[index][2] + ')');
  55. $(this).closest('li').find('.testw5').css('background-color', 'rgb(' + colors[index][0] + ', ' + colors[index][1] + ', ' + colors[index][2] + ')');
  56. $(this).closest('li').find('.testw6').css('background-color', 'rgb(' + colors[index][0] + ', ' + colors[index][1] + ', ' + colors[index][2] + ')');
  57. index++;
  58. }
  59. else {
  60. $(this).css('background-color', 'rgb(' + colors2[index][0] + ', ' + colors2[index][1] + ', ' + colors2[index][2] + ')');
  61. $(this).closest('li').find('.testw5').css('background-color', 'rgb(' + colors2[index][0] + ', ' + colors2[index][1] + ', ' + colors2[index][2] + ')');
  62. $(this).closest('li').find('.testw6').css('background-color', 'rgb(' + colors2[index][0] + ', ' + colors2[index][1] + ', ' + colors2[index][2] + ')');
  63. index++;
  64. }
  65. });
  66.  
  67. }
  68. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement