<script type="text/javascript">
let section = document.querySelectorAll ('.stall');
window.onscroll = magic;
function magic(){
if (window.pageYOffset > 400) {
section.style.width= '20%'
section.style.margin= '-100px 0 0 -200px'
section.style.transition= '1s ease-in-out 0s'
} else {
section.style.width= '10%'
section.style.margin= '0'
}
}</script>
let section = document.querySelectorAll ('.st_img_');
window.onscroll = magic;
function magic(){
section.forEach(function(st_img_){
if (window.pageYOffset > 400) {
section.style.width= '20%'
section.style.margin= '-100px 0 0 -200px'
section.style.transition= '1s ease-in-out 0s'
} else {
section.style.width= '10%'
section.style.margin= '0'
}
}
}
const elements = [...document.querySelectorAll('.stall')];
for (const section of elements) {
console.log(section);
}
for (const section of document.querySelectorAll('.stall')) {
console.log(section);
}console.log([...{[Symbol.iterator]() {
let i = 0;
return {next() {
console.log('spread', i);
return {value: i++, done: i > 10};
}};
}}]);
for(const item of {[Symbol.iterator]() {
let i = 0;
return {next() {
console.log('for of', i);
return {value: i++, done: i > 10};
}};
}}) console.log('for body', item);
const elements = Array.from(document.querySelectorAll('.stall'));
for (const section of elements) {
console.log(section);
}var elements = Array.from(document.querySelectorAll('.stall'));
for (var _i = 0, _elements = elements; _i < _elements.length; _i++) {
var section = _elements[_i];
console.log(section);
}
Результат аналогичен
const elements = Array.from(document.querySelectorAll('.stall'));
for (const section of elements) {
console.log(section);
}var elements = Array.from(document.querySelectorAll('.stall'));
for (var _i = 0, _elements = elements; _i < _elements.length; _i++) {
var section = _elements[_i];
console.log(section);
}
Можно еще ускорить, избавить от преобразования к массиву.О чем и речь...
Я захотел написать так, и я так написалВпрочем понятно...