вы можете просто использовать JavaScript для этого. Результатом SharePoint является html/javascript, поэтому вы не должны обращаться с этим другим, чем другой CMS/веб-сайт.
В вашем document.ready или document.load событие называют эту функцию:
Просто наблюдая за месяц:
function setBGBySeason() {
var date = new Date();
month = date.getMonth();
winter = '12,1,2,';
spring = '3,4,5,';
summer = '6,7,8,';
fall = '9,10,11,';
season = 'unknown';
if (winter.indexOf(month) != -1) {
season = 'winter';
bgcolor = "#003399";
} else if (spring.indexOf(month) != -1) {
season = 'spring';
bgcolor = "#ffffcc";
} else if (summer.indexOf(month) != -1) {
season = 'summer';
bgcolor = "#ffff00";
} else if (fall.indexOf(month) != -1) {
season = 'fall';
bgcolor = "#f2ffe6";
}
document.body.style.background = bgcolor;
console.log(season);
}
Просмотр полной даты:
var dates = {
convert:function(d) {
// Converts the date in d to a date-object. The input can be:
// a date object: returned without modification
// an array : Interpreted as [year,month,day]. NOTE: month is 0-11.
// a number : Interpreted as number of milliseconds
// since 1 Jan 1970 (a timestamp)
// a string : Any format supported by the javascript engine, like
// "YYYY/MM/DD", "MM/DD/YYYY", "Jan 31 2009" etc.
// an object : Interpreted as an object with year, month and date
// attributes. **NOTE** month is 0-11.
return (
d.constructor === Date ? d :
d.constructor === Array ? new Date(d[0],d[1],d[2]) :
d.constructor === Number ? new Date(d) :
d.constructor === String ? new Date(d) :
typeof d === "object" ? new Date(d.year,d.month,d.date) :
NaN
);
},
compare:function(a,b) {
// Compare two dates (could be of any type supported by the convert
// function above) and returns:
// -1 : if a < b
// 0 : if a = b
// 1 : if a > b
// NaN : if a or b is an illegal date
// NOTE: The code inside isFinite does an assignment (=).
return (
isFinite(a=this.convert(a).valueOf()) &&
isFinite(b=this.convert(b).valueOf()) ?
(a>b)-(a<b) :
NaN
);
},
inRange:function(d,start,end) {
// Checks if date in d is between dates in start and end.
// Returns a boolean or NaN:
// true : if d is between start and end (inclusive)
// false : if d is before start or after end
// NaN : if one or more of the dates is illegal.
// NOTE: The code inside isFinite does an assignment (=).
return (
isFinite(d=this.convert(d).valueOf()) &&
isFinite(start=this.convert(start).valueOf()) &&
isFinite(end=this.convert(end).valueOf()) ?
start <= d && d <= end :
NaN
);
}
}
function setBGBySeason() {
var date = new Date();
var year = date.getFullYear();
var springStart = new Date(year + "-03-21");
var summerStart = new Date(year + "-06-21");
var fallStart = new Date(year + "-09-21");
var winterStart = new Date(year + "-12-21");
var season = "unknown";
var bgcolor = "white";
if(dates.inRange(date, springStart, summerStart)){
season = 'Spring';
bgcolor = "#ffffcc";
}else if(dates.inRange(date, summerStart, fallStart)){
season = 'Summer';
bgcolor = "#ffff00";
}else if(dates.inRange(date, fallStart, winterStart)){
season = 'Fall';
bgcolor = "#f2ffe6";
}else if(dates.inRange(date, winterStart, springStart)){
season = 'Winter';
bgcolor = "#003399";
}
document.body.style.background = bgcolor;
console.log(season);
}
Так что происходит:
- Получение даты сегодня
- извлекая месяц даты
- В зависимости от месяца мы можем определить сезон
- Настройка цвета для каждого сезона
- Использование document.body.style.background , мы устанавливаем цвет фона
PS: Я нашел даты объекта на StackOverflow, не написал его сам, но, кажется, работает, как и должно
спасибо большое ,, но я хочу, чтобы изменить _background image_ между определенными датами, как (весна _from 21-Мар до 21-Jun) – user6246510
нет никакого способа сделать это в файле CSS ,,,,, – user6246510
нет способа сделать это в файле CSS ,,,,, – user6246510