필자는 스크립트를 만들뿐만 아니라 일부 변경 포함되어 있습니다. 당신의 코드에서, 이벤트는 모든 scrollmovement에 의해 trigged되기 때문에 '작은'여러 개의 클래스를 추가 할 것입니다. 필자는 클래스를 추가했는데, 먼저이 클래스가 설정되어 있는지 확인합니다. 설정되지 않은 경우 스크롤의 색상이 변경됩니다. 당신이 '검사', 색상이 아닌가요 경우 아주 멋진 될 수있는 모든 scrollmovement을 바꿀 것을 제거하면 당신이 원하는 경우 간질 :
이
// array with the colors, you can add the colors here.
var colors = ["red", "blue", "yellow", "black", "green"];
$(window).scroll(function() {
if ($(document).scrollTop() == 0)
{
//if scrollbar is at the top (doing nothing atm)
}
else if($("#header_nav").hasClass("colorSet"))
{
//if the colorSet class has been apended (remove this, if you want some fun :))
}
else
{
//first, add the class, so we know we do not have to walk tru this anymore.
$('#header_nav').addClass('colorSet');
// Apend a CSS background-color based on a rand function on our color array
$('#header_nav').css("background-color", colors[Math.floor(Math.random() * colors.length)]);
}
});
이제 문 경우 첫번째 변경할 수 있습니다 (scrollTop()). 여기에서 colorSet 클래스를 제거하면 누군가가 아래로 스크롤하면 다시 새로운 색상을 얻을 수 있습니다.
임의의 색상을 가진 여러 클래스의 경우;
// array with the colors, you can add the colors here.
var colors = ["red", "blue", "yellow", "black", "green"];
$(window).scroll(function() {
if ($(document).scrollTop() == 0)
{
//if scrollbar is at the top (doing nothing atm)
}
else if($("#header_nav").hasClass("colorSet"))
{
//if the colorSet class has been apended (remove this, if you want some fun :))
}
else
{
//first, add the class, so we know we do not have to walk tru this anymore.
$('#header_nav').addClass('colorSet');
// Apend a CSS background-color based on a rand function on our color array
$('#header_nav').css("background-color", colors[Math.floor(Math.random() * colors.length)]);
$('.header').css("background-color", colors[Math.floor(Math.random() * colors.length)]);
$('.header.tiny').css("background-color", colors[Math.floor(Math.random() * colors.length)]);
}
});
그리고 동일한 색상을 공유하는 여러 클래스의 경우. "RGBA (varR, VARG, varR, 투명성);"
// array with the colors, you can add the colors here.
var colors = ["red", "blue", "yellow", "black", "green"];
$(window).scroll(function() {
if ($(document).scrollTop() == 0)
{
//if scrollbar is at the top (doing nothing atm)
}
else if($("#header_nav").hasClass("colorSet"))
{
//if the colorSet class has been apended (remove this, if you want some fun :))
}
else
{
//first, add the class, so we know we do not have to walk tru this anymore.
$('#header_nav').addClass('colorSet');
var color = colors[Math.floor(Math.random() * colors.length)];
// Apend a CSS background-color based on a rand function on our color array
$('#header_nav').css("background-color", color );
$('.header').css("background-color", color);
$('.header.tiny').css("background-color", color);
}
});
정확한 색상은 무엇을 의미합니까? 미리 결정된 색, 또는'# 3FA3E5'와 같은 것을 의미합니까? –
목록처럼, 예를 들어 #ff0, # f0f, # 0ff, # 0f0 등을 사용하고 스크립트는이 색상 중 하나를 선택해야합니다. – barnade95