0
Problem in javascript ☹️
My code won't Run in Safari browser Problem line 24 const images = document.querySelectorAll("[data-src]"); function preloadImage(img) { const src = img.getAttribute("data-src"); if (!src){ return; } img.src = src; } const imgOptions = { threshold: 0, rootMargin: "0px 0px 300px 0px" }; /// Problem Line 24 const imgObserver = new IntersectionObserver((entries,imgObserver) => { entries.forEach(entry => { if (!entry.isIntersecting){ return; } else { preloadImage(entry.target); imgObserver.unobserve(entry.target); } Can any body Fix this?
7 Answers
+ 2
That's your browser/Js engine doesn't support the arrow function ES6 feature... you should rewrite it with "classic" (explicit -- full typed "function() {}" format) function declaration or expression ;)
+ 2
Where is your code, can you prepare your attempt here on playground please
+ 2
tnx visph 👌🏻🙏🏻
+ 1
And what say exactly the error message(s)? I guess it's not "problem line 24" or "problem line 18" without more details ;P
Anyway, all what we could guess here, that 's you're probably missing the library providing the definition of IntersectionObserver, either because you don't or bad link it, or the ressource is unavailable for some reason (could be because you run your code in https but you link a js file trough http -- secure vs not secure requests ^^)
0
i'm not javascript Developer
This is all code of loder.js file
const images = document.querySelectorAll("[data-src]");
function preloadImage(img) {
const src = img.getAttribute("data-src");
if (!src){
return;
}
img.src = src;
}
const imgOptions = {
threshold: 0,
rootMargin: "0px 0px 300px 0px"
};
/// Problem Line 24
const imgObserver = new IntersectionObserver((entries,imgObserver) => {
entries.forEach(entry => {
if (!entry.isIntersecting){
return;
} else {
preloadImage(entry.target);
imgObserver.unobserve(entry.target);
}
0
if you open this code in notpad++ the problem is in line 18
0
error is Syntaxerror : Unexpected tokan '=>'