-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplugin-screen-color.js
64 lines (53 loc) · 2.18 KB
/
plugin-screen-color.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
(function ($) {
$.fn.scrollColorChange = function (options) {
var settings = $.extend({
colors: [
{ name: "blue", color: "rgb(43, 174, 226)" },
{ name: "yellow", color: "rgb(177, 226, 43)" },
{ name: "white", color: "rgb(255, 255, 245)" },
{ name: "red", color: "rgb(214, 40, 40)" },
{ name: "black", color: "#080808" },
],
initialColor: "red", // Adiciona uma nova opção para a cor inicial
textColors: [ // Adicione um array de cores de texto de contraste predefinidas
{ name: "blue", color: "#66250B" },
{ name: "yellow", color: "#080808" },
{ name: "white", color: "#020827" },
{ name: "red", color: "#fdf5e6" },
{ name: "black", color: "#fff" },
],
}, options);
var currentColorIndex = settings.colors.findIndex(color => color.name === settings.initialColor) || 0;
function changeColor() {
currentColorIndex = (currentColorIndex + 1) % settings.colors.length;
updateColor();
}
function updateColor() {
var selectedColor = settings.colors[currentColorIndex].color;
var selectedTextColor = settings.textColors[currentColorIndex].color;
$("body").css({
"background-color": selectedColor,
"color": selectedTextColor,
});
// Adiciona a classe 'rotacionar' ao display
$(".scroll-container").addClass("rotacionar");
// Remove a classe 'rotacionar' após 1 segundo
setTimeout(function () {
$(".scroll-container").removeClass("rotacionar");
}, 1000);
}
return this.each(function () {
var $this = $(this);
$this.on("click", function () {
changeColor();
});
$(document).keydown(function (e) {
if (e.which === 40) {
changeColor();
}
});
// Inicia com a cor inicial
updateColor();
});
};
})(jQuery);