Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
61
Help us understand the problem. What is going on with this article?
@tknakatsu

レスポンシブなイメージマップの作成

More than 5 years have passed since last update.

1枚の画像に複数のリンクを付けるイメージマップですが、htmlとcssだけではレスポンシブに対応できないので「jQuery RWD Image Maps」というプラグインを使用します。

jQuery RWD Image Maps
https://github.com/stowball/jQuery-rwdImageMaps

実装サンプル

<script type="text/javascript" src="jquery.rwdImageMaps.min.js"></script>
html
<img src="img.png" width="800" height="115" usemap="#ImageMap">
<map name="ImageMap">
    <area shape="rect" coords="200,0,500,110" href="#" alt="" />
</map>
css
img[usemap] {
    max-width: 100%;
    height: auto;
}
js
$(document).ready(function(e) {
    $('img[usemap]').rwdImageMaps();
})

注意点はimgタグに画像が表示上の最大幅となる時widthheightを指定することです。

areaタグの座標の作成は「HTML Imagemap Generator」が便利です。
HTML Imagemap Generatorを使用する際は表示上の最大幅の画像を使用してください。

HTML Imagemap Generator
http://labs.d-s-b.jp/ImagemapGenerator/

61
Help us understand the problem. What is going on with this article?
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away

Comments

No comments
Sign up for free and join this conversation.
Sign Up
If you already have a Qiita account Login
61
Help us understand the problem. What is going on with this article?