Skip to content
This repository has been archived by the owner on Oct 10, 2024. It is now read-only.

Update src does not work #85

Open
Andries-Smit opened this issue Jun 21, 2017 · 7 comments
Open

Update src does not work #85

Andries-Smit opened this issue Jun 21, 2017 · 7 comments
Labels

Comments

@Andries-Smit
Copy link

Thanks for this solution.

An improvement is to support updating the src attribute. At the moment it does not update the bg image url when the src is updated.

https://github.com/bfred-it/object-fit-images/blob/master/index.js#L118
By swapping the src and the currentSrc fixed it for me.
el.style.backgroundImage = "url(\"" + ((ofi.img.src || ofi.img.currentSrc).replace(/"/g, '\\"')) + "\")";

Though I cant oversee the full effect. #84

Cheers.

@fregante
Copy link
Owner

At the moment it does not update the bg image url when the src is updated.

Are you using only src or srcset in your tests? Can you provide a jsfiddle showing the issue?

@Andries-Smit
Copy link
Author

Thanks for the quick response

https://jsbin.com/goxazineti/1/edit?html,output

  • run in Chome the cat will be updated gray to ginger
  • run in IE you keep the gray cat.

If you dont like cats i could replace the images with dogs,.

@fregante
Copy link
Owner

fregante commented Jun 21, 2017

No, I like cats 🙀

@alejandroiglesias
Copy link

Any updates on this? I can confirm this issue on Edge.

@fregante
Copy link
Owner

fregante commented Sep 7, 2017

Sorry it took so long. Yeah the bug is confirmed, however that is not the only way to change the src.

Changing the src property instead works and it's always the preferred method:

img.src = "new=image.jpg";

https://jsbin.com/gipuzolumo/edit?html,output

@fregante fregante added the bug label Sep 7, 2017
@alejandroiglesias
Copy link

@bfred-it thing is I'm using Angular.js and the ng-src attribute directive, which sets the src attribute once the object data is available.

@benmccallum
Copy link

I'm doing a simple lazy-load, setting the src to the real image (from a spacer image) as the user scrolls down and getting this too. Had to manually call objectFitImages(myImages) again.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

4 participants