Description:
, cookie, cookie.
HTML
<h1>My dog is <span id="wss"></span></h1>
CSS
#wss {
opacity: 0;
webkit-transition:opacity 1.0s linear 0s;
transition:opacity 1.0s linear 0s;
}
JS
var wss_i=0;
var wss_array= ['<img src="http://placehold.it/350x150" />','<img src="http://placehold.it/350x250" />','<img src="http://placehold.it/350x100" />'];
function getCookie(c_name) {
var c_value = document.cookie;
var c_start = c_value.indexOf(" " + c_name + "=");
if (c_start == -1) {
c_start = c_value.indexOf(c_name + "=");
}
if (c_start == -1) {
c_value = null;
} else {
c_start = c_value.indexOf("=", c_start) + 1;
var c_end = c_value.indexOf(";", c_start);
if (c_end == -1) {
c_end = c_value.length;
}
c_value = unescape(c_value.substring(c_start, c_end));
}
return c_value;
}
function setCookie(c_name, value, exdays) {
var exdate = new Date();
exdate.setDate(exdate.getDate() + exdays);
var c_value = escape(value) + ((exdays == null) ? "" : "; expires=" + exdate.toUTCString());
document.cookie = c_name + "=" + c_value;
}
function wssSlide(){
wss_elem.innerHTML = wss_array[wss_i];
wss_elem.style.opacity = 1;
setTimeout('wssNext()', 9000);
}
function wssNext() {
wss_i++;
wss_elem.style.opacity = 0;
setCookie('image', wss_i, 365);
if(wss_i > (wss_array.length - 1)) {
wss_i = 0;
}
setTimeout('wssSlide()', 1000) ;
}
window.onload=function () {
wss_elem = document.getElementById("wss");
if(getCookie('image') != null) {
wss_i = getCookie('image');
}
wssSlide();
}