var pauseButton = document.querySelector(".pause-button"),
start = Date.now(),
duration = 3000,
timePassed,
paused;
var timer = setInterval(change, duration);
pauseButton.addEventListener("click", function() {
if (!paused) {
clearInterval(timer);
timePassed = Date.now() - start;
paused = true;
} else {
setTimeout(function() {
timer = setInterval(change, duration);
}, duration - timePassed);
paused = false;
}
}, false);
function change() {
// ...
}
function mergeCells(table) {
var head = table.rows[0],
body = table.rows[1],
resultHead = "",
resultBody = "",
matches = {};
for (var i = 0; i < body.cells.length; i++) {
var headCellText = head.cells[i].textContent,
bodyCellText = body.cells[i].textContent,
match = matches[bodyCellText] || (matches[bodyCellText] = []);
match.push(headCellText);
}
for (var key in matches) {
var match = matches[key],
from = match[0],
to = match[match.length - 1];
if (match.length > 1) {
resultHead += "<td>" + from + "-" + to + "</td>";
} else {
resultHead += "<td>" + from + "</td>";
}
resultBody += "<td>" + key + "</td>";
}
head.innerHTML = resultHead;
body.innerHTML = resultBody;
}
localStorage.setItem("city", cityName);
switch (localStorage.getItem("city")) {
case "Москва":
/* ... */;
break;
case "Санкт-Петербург":
/* ... */;
break;
}
$spinner.fadeOut(350, function() {
$preloader.fadeOut('slow');
});
if ((e.target.nodeName != 'DIV' && e.target.nodeName != 'FIGCAPTION') || e.keyCode == 27) { /* ... */ }
if ((e.target.nodeName != 'DIV' && e.target.nodeName != 'FIGCAPTION' && e.target.nodeName != 'INPUT') || e.keyCode == 27) { /* ... */ }
var image = new Image();
image.src = "image.jpg";
new Image().src = "image.jpg";
function preloadImages() {
for (var i = 0; i < arguments.length; i++) {
new Image().src = arguments[i];
}
}
preloadImages(
"images-1.jpg",
"images-2.jpg",
"images-3.jpg"
);