代码之家  ›  专栏  ›  技术社区  ›  Mark Henry

向天气图添加点

  •  0
  • Mark Henry  · 技术社区  · 15 年前

    我的网站上有一张天气图(JPG),但它并不代表城市。我想增加点(带索引)显示特定的城市。最好的方法是什么?我可以用jquery吗?

    1 回复  |  直到 13 年前
        1
  •  1
  •   Harmen    15 年前

    HTML:

    <div id="weathermap">
        <a class="point pos1" href="/city_1" title="City One"><span class="hide">City one</span><span class="dot">.</span></a>
        <a class="point pos2" href="/city_2" title="City Two"><span class="hide">City two</span><span class="dot">.</span></a>
        <img src="weather.jpg" alt="Weather Map" />
    </div>
    

    CSS:

        #weathermap {
            position: relative;
            padding: 0;
        } 
    
        .point {
            position: absolute;
            line-height: 16px;
        }
    
        span.hide {
            display: none; // Don't show 'city one' on the map
        }
    
        span.dot {
            display: block;
            // This background picture is a simple marker of 16px by 16px
            background: transparent url(marker.png) no-repeat scroll center center;
            width: 16px;
            height: 16px;
            text-indent: -9999px; //Remove the dot to replace it with a marker
        }
    
        .pos1 {
            top: 50px;
            left: 100px;
        }
    
        .pos2 {
            top: 120px;
            left: 10px;
        }
    

    要添加另一个城市,只需添加另一个城市 <a ...> 给它另一个类名,比如pos3。然后你可以添加 .pos3 给你的CSS代码和更改坐标 top left 价值观