Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create an image loading animation? #699

Open
DomeWorld1 opened this issue Jul 29, 2023 · 6 comments
Open

Create an image loading animation? #699

DomeWorld1 opened this issue Jul 29, 2023 · 6 comments
Labels
enhancement New feature or request

Comments

@DomeWorld1
Copy link

DomeWorld1 commented Jul 29, 2023

The Problem

The image loading in the article is very stiff, I hope create an image loading animation.

The Solution

Like Minerva, the image fades in. I think it's a good design.

You can also use image scrolling to lazily load.

@DomeWorld1 DomeWorld1 added the enhancement New feature or request label Jul 29, 2023
@alistair3149
Copy link
Member

We used to have JS lazyloading years ago in the Citizen skin. However, it caused a lot of issues with many wikis so we ended up deferring to use the browser native method instead ($wgNativeImageLazyLoading). However, with the native method, there are no reliable way to tell whether an image is loaded, so there isn't a good way to implement any animation for that.

If anyone knows of a way, please feel free to drop a comment or submit a PR!

@DomeWorld1
Copy link
Author

DomeWorld1 commented Aug 3, 2023

https://starcitizen.tools/
The current devtools console prompt warning is:
[Intervention] Images loaded lazily and replaced with placeholders. Load events are deferred. See https://go.microsoft.com/fwlink/?linkid=2048113

It will delay the triggering of the load event
The solution to the problem that someone else encountered:Candinya/Kratos-Rebirth#144.

@DomeWorld1
Copy link
Author

DomeWorld1 commented Aug 3, 2023

I provide codes that can achieve fade in loading, which have significant limitations😣:

#content img {
	opacity: 0;
	transition: opacity 0.2s ease-in;
}

#content a.image {
    background-color: var( --color-surface-2 );
}
const lazyImages = document.querySelectorAll('img');
lazyImages.forEach(function(image, index) {
	image.classList.add('lazy');
	image.dataset.src = image.src;
	image.removeAttribute('src');
});
var lazyImageObserver = new IntersectionObserver(function(entries, observer) {
	entries.forEach(function(entry) {
		if (entry.isIntersecting) {
			var lazyImage = entry.target;
			lazyImage.src = lazyImage.dataset.src;
			lazyImage.classList.remove('lazy');
			lazyImageObserver.unobserve(lazyImage);
			lazyImage.style.opacity = '1';
		}
	});
});
lazyImages.forEach(function(lazyImage, index) {
	lazyImageObserver.observe(lazyImage);
});

@DomeWorld1
Copy link
Author

DomeWorld1 commented Aug 3, 2023

I found that the MobileFrontend comes with it, can use it directly on the desktop? Because many people don't use MobileFrontend. You can take a look if you have time🐣
https://github.com/search?q=repo%3Awikimedia%2Fmediawiki-extensions-MobileFrontend+lazy&type=code

@alistair3149
Copy link
Member

I'm aware of the MF implementation and as I mentioned above, we had a similar implementation a long time ago. However, it was removed as the native browser implementation is more superior and has noscript support.

It is unlikely that we will go back to the JS lazyload implementation, given that core already supports the native method.

@alistair3149
Copy link
Member

https://starcitizen.tools/ The current devtools console prompt warning is: [Intervention] Images loaded lazily and replaced with placeholders. Load events are deferred. See https://go.microsoft.com/fwlink/?linkid=2048113

I think it seems to have affected the loading of images to some extent now. The solution to the problem that someone else encountered:Candinya/Kratos-Rebirth#144.

I'm not sure whether it is a bug, it seems to be exclusive to Microsoft Edge and only popping up recently. There's a relevant task that is being tracked: https://phabricator.wikimedia.org/T341480

Either way it is a MediaWiki core implementation and is unrelated to the Citizen skin, it is more suitable to submit the relevant info to that task.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants