<button>click me</button>
button {
background: green;
}
@keyframes xxx {
0% { background-color: red; }
100% { background-color: transparent; }
}
.xxx {
animation: xxx 2s;
}
$('button').on({
click() {
$(this).addClass('xxx');
},
animationend() {
$(this).removeClass('xxx');
},
});
for (var i = 0; i < 10; i++) {
setTimeout(function() {
alert(+this);
}.bind(i), 100);
}
for (let i = 0; i < 10; i++) {
setTimeout(function() {
alert(i);
}, 100);
}
for (var i = 0; i < 10; i++) {
setTimeout(alert, 100, i);
}
for (var i = 0; i < 10; i++) {
setTimeout(new Function(`alert(${i})`), 100);
}
for (var i = 0; i < 10; i++) {
setTimeout(function() {
alert(i++);
}, 100);
}
i = 0;
$('body').on('click', function(e) {
var
$target = $(e.target),
isMark = $target.hasClass('mark'),
isActive = $target.hasClass('active');
if (!isMark || !isActive) {
$('.mark.active +.tooltip').fadeOut();
$('.mark.active').removeClass('active');
}
if (isMark && !isActive) {
$target.addClass('active');
$('.mark.active +.tooltip').fadeIn();
}
});
он не работает
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(hConsole, color);
SELECT `date`
FROM `foo`
WHERE `id` >= (
SELECT `id`
FROM `foo`
WHERE `date` < now()
ORDER BY `id` DESC
LIMIT 1
)
SELECT t2.s1
FROM (
SELECT
t1.id,
t1.s1,
IF (@max = 1, @max := t1.seq, @max := @max) AS "max1",
IF (t1.seq = 1, @max := 1, @max := @max) AS "max2"
FROM (
SELECT
(SELECT @id := @id + 1) AS "id",
s1,
IF (s1 = @prev + 1, @seq := @seq + 1, @seq := 1) AS "seq",
(SELECT @prev := s1) AS "prev"
FROM `table`,
(SELECT @id := 0, @seq := 0, @prev := null) AS init
) AS t1,
(SELECT @max := 1) AS init
ORDER BY t1.id DESC
) AS t2
WHERE t2.max1 >= 3
ORDER BY t2.id
s1 | n
1 3
2 3
3 3
7 1
12 1
22 2
23 2
5 4
6 4
7 4
8 4
SELECT s1 FROM `table` WHERE n > 2
<div data-num="2350" data-step="5" class="number">0</div>
$(window).scroll(function() {
var $win = $(window);
if ($('#counter').offset().top < $win.scrollTop() + 200) {
$win.off('scroll');
$('.number').addClass('viz').each(function() {
var
i = 0,
num = +this.dataset.num,
timeStep = 1000 / num,
valStep = +this.dataset.step || 1,
interval = setInterval(function($el) {
if ((i += valStep) >= num) {
clearInterval(interval);
}
$el.html(Math.min(i, num));
}, timeStep, $(this));
});
}
});
var steps = 100;
$(window).scroll(function() {
var $win = $(window);
if ($('#counter').offset().top < $win.scrollTop() + 200) {
$win.off('scroll');
$('.number').addClass('viz').each(function() {
var
i = 0,
num = +this.dataset.num,
valStep = num / steps,
interval = setInterval(function($el) {
if ((i += valStep) >= num) {
clearInterval(interval);
}
$el.html(Math.floor(Math.min(i, num)));
}, 20, $(this));
});
}
});
querySelectorAll
возвращает коллекцию элементов, никакого addEventListener
у неё нет - его надо вызывать отдельно у каждого элемента.e.classList
? e
- это объект события, а не элемент DOM-дерева.const elems = document.querySelectorAll('nav#menu_3 > ul > li');
elems.forEach(n => n.addEventListener('mouseover', onMouseover));
function onMouseover() {
elems.forEach(n => {
n.classList.toggle('zoomed', this === n);
n.classList.toggle('nozoomed', this !== n);
});
}
INSERT INTO Items SET `itemid` = 'SELECT MAX(`itemid`) FROM `Items`', ...
(SELECT MAX(`itemid`) FROM `Items`)
INSERT INTO Items(itemid, title, type)
SELECT MAX(itemid), <значение для title>, <значение для type> FROM Items
connection.query('INSERT INTO Items(itemid, title, type) SELECT MAX(itemid), ?, ? FROM Items', [ data.title, data.group ])
<a href="#" class="menu-trigger" data-list="#menu">Menu</a>
<a href="#" class="menu-trigger" data-list="#contacts">Contacts</a>
<ul id="menu" class="list">...</ul>
<ul id="contacts" class="list">...</ul>
$('.menu-trigger').click(function() {
var list = this.dataset.list;
$(this).parent().find('.list').not(list).slideUp(0);
$(list).slideToggle(500);
});
$(window).resize(function() {
if ($(window).width() > 500) {
$('.list').removeAttr('style');
}
});