Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
105 views
in Technique[技术] by (71.8m points)

javascript - prevent image's upload when it's hidden

I'm working on responsive web application, and when I use mobile devices I have noticed that the hiding images are uploaded in the network of the browser. Therefore is not a good thing for the performance of the application and i want to stop upload these images when im using mobile device. In my HTML I have used a css style for each device and variables to display the image in normal browser and I hide it in mobile device (using *ngIf) but it doesn't prevent it from uploading the image. can you please help to solve this optimization issue and what is the best way to do it. I'm working with Angular 8 and i don't want to use jQuery.

Thanks in advance

question from:https://stackoverflow.com/questions/65920528/prevent-images-upload-when-its-hidden

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
loadIt() {
    if(imageIsInFront) {
    mustBeLoaded = true;
    }
}

<div *ngFor="let img of images, let i=index">
  <img *ngIf="mustBeLoaded" (load)="loadIt()" [src]="img">
</div>

not tested


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...