$(document).ready(function() {
var COLOR = {
fadeBackground: function(config){
var totalStartPoint= config.startRED+config.startGREEN+config.startBLUE;
var totelEndPoint = config.endRED+config.endGREEN+config.endBLUE;
if(totalStartPoint < totelEndPoint){
var clearTime = setInterval(
function (){
//elem.css("background-color", "rgb("+color.startRED+","+color.startGREEN+","+color.startBLUE+")");
document.getElementById('jsFullAccessColor').style.background ="rgb("+config.startRED+","+config.startGREEN+","+config.startBLUE+")";
if(config.startRED < config.endRED){
config.startRED++;
}
if(config.startGREEN < config.endGREEN){
config.startGREEN++;
}
if(config.startBLUE < config.endBLUE){
config.startBLUE++;
}
if(config.startRED == config.endRED && config.startGREEN == config.endGREEN && config.startBLUE == config.endBLUE){
clearTimer(clearTime);
}
}, config.speed);
}
if(totalStartPoint > totelEndPoint){
var clearTime = setInterval(
function (){
document.getElementById(config.element).style.background ="rgb("+config.startRED+","+config.startGREEN+","+config.startBLUE+")";
if(config.startRED > config.endRED){
config.startRED--;
}
if(config.startGREEN > config.endGREEN){
config.startGREEN --;
}
if(config.startBLUE > config.endBLUE){
config.startBLUE--;
}
if(config.startRED == config.endRED && config.startGREEN == config.endGREEN && config.startBLUE == config.endBLUE){
clearTimer(clearTime);
}
}, config.speed);
}
}
}
function clearTimer(timerId){
clearInterval (timerId);
}
$(".domEleement").on("click",function (){
var config ={
//color starting point
startRED:172,
startGREEN:210,
startBLUE:247,
//color end point
endRED:255,
endGREEN:255,
endBLUE:255,
//element
element:"jsFullAccessColor",
//speed
speed:20
}
COLOR.fadeBackground(config);
});
});