call different imagecropper crop at different browser widths
Hi Everyone,
I have a banner that calls the image from imagecropper. The banner is created from an xslt macro. I have been searching for quite a while on how to change the image crop to a different image crop when the browser width gets above a certain width.
ie:
> 1200px wide - show homepageBannerWide cropsize
< 1199px wide - show homepageBannerCrop cropsize
Is there anyway to find the browser width from xslt? If xslt can find the browser width then I can put in a when statement.
If not then is there any way to render a macro from inside a javascript call? I could make a second macro, with the different crop in it, and then call in that macro from inside a javascript call, like this:
<script>
$(window).on("resize", function() {
if ($(window).width() >= 1200) {
RENDER MACRO 1 HERE
}
if ($(window).width() <= 1199) {
RENDER MACRO 2 HERE
}
});
</script>
I don't believe the browser width is sent to the server, which makes sense considering the user can resize their browser after the page has loaded.
Assuming there is some reason you can't use picture tags, media queries, or Slimmage/Slimsy, I don't see why you'd need to add the JavaScript to the macro itself.
Why not have the JavaScript load on every page, then have it find elements with a certain class and dynamically apply the correct image on page load or resize? So, if you had markup like this:
You could have the JavaScript scan the page for the dynamic-image class (should be easy enough, since you appear to be using jQuery), then replace those elements with an image element that has the src set to one of the data attributes (depending on the browser width size).
Another alternative, though I wouldn't recommend it over the above solution, would be to add JavaScript directly to the XSLT.
Another options is to instead of outputting a img-tag you out put a div and set the image as background. Then with media queries you can change the background depending on screen widt
Managed to work it out with Media Queries (thanks Nicholas for the reminder). I originally thought I would do it that way and after not finding the solution I thought of jquery. Anyway, I'm a moron and should have done more research before posting a question.
I simply put the area that calls in the image crop in the xslt in several different times (3 different divs in my case as I wanted 3 different crops), and added in a different css class to each of those divs, then hid and showed the divs with media queries.
call different imagecropper crop at different browser widths
Hi Everyone, I have a banner that calls the image from imagecropper. The banner is created from an xslt macro. I have been searching for quite a while on how to change the image crop to a different image crop when the browser width gets above a certain width.
ie:
Is there anyway to find the browser width from xslt? If xslt can find the browser width then I can put in a when statement.
If not then is there any way to render a macro from inside a javascript call? I could make a second macro, with the different crop in it, and then call in that macro from inside a javascript call, like this:
Thanks, Wade.
Depends on what browsers you need to support, but you can use the HTML
Last week a package was released for helping rendering this tag : https://our.umbraco.org/projects/developer-tools/umbraco-picture-helper/
I haven't used that.
Dave
Hi Dave, Thanks for the reply. Unfortunately the browser support for it doesn't suit my client. I'll look into it for other projects though.
I don't believe the browser width is sent to the server, which makes sense considering the user can resize their browser after the page has loaded.
Assuming there is some reason you can't use picture tags, media queries, or Slimmage/Slimsy, I don't see why you'd need to add the JavaScript to the macro itself.
Why not have the JavaScript load on every page, then have it find elements with a certain class and dynamically apply the correct image on page load or resize? So, if you had markup like this:
You could have the JavaScript scan the page for the
dynamic-image
class (should be easy enough, since you appear to be using jQuery), then replace those elements with an image element that has thesrc
set to one of the data attributes (depending on the browser width size).Another alternative, though I wouldn't recommend it over the above solution, would be to add JavaScript directly to the XSLT.
Another options is to instead of outputting a img-tag you out put a div and set the image as background. Then with media queries you can change the background depending on screen widt
Dave
Managed to work it out with Media Queries (thanks Nicholas for the reminder). I originally thought I would do it that way and after not finding the solution I thought of jquery. Anyway, I'm a moron and should have done more research before posting a question.
I simply put the area that calls in the image crop in the xslt in several different times (3 different divs in my case as I wanted 3 different crops), and added in a different css class to each of those divs, then hid and showed the divs with media queries.
For those interested in the code:
If you don't know how to use imagecropper in Umbraco 7 with xslt, check out this thread: https://our.umbraco.org/forum/developers/xslt/48101-How-to-get-image-cropper-value
Cheers, Wade.
is working on a reply...