Answer the question
In order to leave comments, you need to log in
AngularJS: What's the best way to load different versions of images?
Hello. The essence of the question is this: there are two versions of the layout (<992px and >992px respectively), I want to load only x or 2 images for a certain version (we are talking about the img tag, not about background-image).
What solution do I see:
// в шаблоне
<img ng-src="/images/pic5-{{screen}}.jpg">
//в контроллере или директиве
$scope.screen = $window.screen.width >=992 ? 'lg' : 'sm'
$window.bind('resize', function {
$scope.screen = $window.screen.width >=992 ? 'lg' : 'sm'
})
Answer the question
In order to leave comments, you need to log in
I would at least wrap all this goodness in a directive in which I would load it with AJAX if necessary, so that the picture does not disappear for an indefinite time when resizing.
At the resize event, I would check if something has changed.
Those. if it was already less than 992 and less is left - do nothing.
And with changes, I would throw event. This is much more versatile than binding to $scope.
The directive would accordingly be subscribed to this event.
For this purpose, use the element <pictures>
. It's a native HTML approach to accomplish this task. It allows you to write media queries directly in the markup... and more. For more information, I advise you to watch the report of Vadim Makeev on this topic: https://www.youtube.com/watch?v=Szo-2D7TtEU
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question