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

Responsive images with srcset #77

Open
mprofitlich opened this issue Dec 28, 2018 · 2 comments
Open

Responsive images with srcset #77

mprofitlich opened this issue Dec 28, 2018 · 2 comments

Comments

@mprofitlich
Copy link

Issue #41 was similar and got closed but I could not find a solution yet, although the closing comment states a PR had a fix.

I understand the script expects the image to be at the image map's size. If that's not the case the scale calculated factor is wrong. I accept to loose some automation and I added data attributes to the image map that give the original size.

// Image Map in HTML with data attributes
<map name="map-name" data-map-width="950" data-map-height="690">

// var scalingFactor
width  : image.width  / mapOriginalWidth,
height : image.height / mapOriginalHeight

// function setup
mapOriginalHeight     = map.getAttribute("data-map-height");
mapOriginalWidth      = map.getAttribute("data-map-width");

// var
mapOriginalHeight = null,
mapOriginalWidth = null;
@davidjbradshaw
Copy link
Owner

Those data attributed are not supported, why not just resize the image in PhotoShop? Or calculate the map coordinates from the actual size of the image?

@mprofitlich
Copy link
Author

On which image the script bases its calculation when using srcset? Here's a usecase:

<img src="/slir/w100/bilder/imagename.jpg"
    usemap="#image-map"
    srcset="
        /slir/w400/bilder/imagename.jpg 400w,
        /slir/w600/bilder/imagename.jpg 600w,
        /slir/w1000/bilder/imagename.jpg 1000w,
        /slir/w1500/bilder/imagename.jpg 1500w,
        /slir/w2000/bilder/imagename.jpg 2000w,
        /slir/w3000/bilder/imagename.jpg 3000w,
        /slir/w4000/bilder/imagename.jpg 4000w,
        /slir/w5000/bilder/imagename.jpg 5000w,
        /slir/w5500/bilder/imagename.jpg 5500w,
        "
    sizes="100vw"
>

The images are calculated by an image resizer automatically. Does the script use the src chosen by the browser or the normal src tag? If it uses the normal src then I redraw my issue. It would then be helpful to add this information to the documentation, for example:

Responsive Images (srcset)
The script calculates the imagemap based on the dimensions of the image given by the normal src attribute. This image needs to have the same dimensions as used for the creation of the imagemap.

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

No branches or pull requests

2 participants