7

ウィンドウのサイズ変更イベントでイメージ マップのサイズを変更しようとしています。私が得た最も近い方法は、マウスクリックイベントを使用することですが、私がやっていることのためにウィンドウのサイズを変更する必要があります。Firefox 3.5.5 を使用しています

私はjqueryを多少使用しています。これが私の例です-ウィンドウのサイズ変更でサイズを変更したいエリアボタンは左上にあります(クリックしてマップとエリアボタンのサイズを変更します):

http://www.whitebrickstudios.com/foghornstour/imagemap3.html

どんな助けでも大歓迎です!ありがとう、リッチ

4

8 に答える 8

4

すべてのイベントですべてのマップポイントを再構築するための簡単な関数を作成しました。これを試して

function mapRebuild(scaleValue) {
    var map = $("#imgmap"); // select your map or for all map you can choose $("map").each(function() { map = $(this);.....})
    map.find("area").each(function() { // select all areas
        var coords = $(this).attr("coords"); // extract coords
            coords = coords.split(","); // split to array
        var scaledCoords = "";
        for (var coord in coords) { // rebuild all coords with scaleValue
              scaledCoords += Math.floor(coords[coord] * scaleValue) + ",";
            }
        scaledCoords = scaledCoords.slice(0, -1); // last coma delete
        $(this).attr("coords", scaledCoords); // set new coords
        });
    }

scaleValueは、oldWindowWidth/newWindowWidthとして計算できます。もちろん、ウィンドウのサイズ変更時にoldWindowWidthの値を保持する必要があります。たぶん私の解決策は時間通りではありませんが、これが誰かに役立つことを願っています

于 2013-01-29T05:15:01.017 に答える
1

あなたが望むものは http://home.comcast.net/~urbanjost/semaphore.htmlにあると思います

ここでは、画像の表示サイズが変更されたときに画像マップの座標を変更する方法のさまざまな例を示します。

于 2009-12-24T07:21:50.673 に答える
1

これは古いスレッドですが、類似または同一の問題の解決策を探している人にとっては、ImageMapster jQuery プラグインが最も簡単な解決策を提供するようです。次のように、サイズ変更メソッド (必要に応じてサイズ変更をアニメーション化することもできます) を使用して、イメージ マップと共にイメージのサイズを変更できます。

$('img').mapster( 'resize', newWidth, newHeight, resizeTime);

ImageMapster のデモページに、ブラウザ ウィンドウの変更に応じて画像とそのマップのサイズを変更する方法を示す jsFiddleへのリンクがあります。

于 2012-12-23T19:58:48.793 に答える
0

Viktor の回答の修正版として、このバージョンは複数のサイズ変更を処理できます。将来のサイズ変更と比較するための初期値を保存します。これもwaitForFinalEventを使用するため、サイズ変更時に何度も実行されることはありません。



    var mapImg = $('#mapImg');
    var naturalWidth = 1200; // set manually to avoid ie8 issues
    var baseAreas = new Array();
    var scaleValue = mapImg.width() / naturalWidth;

    $(window).resize( function() {
        waitForFinalEvent( function() {
            scaleValue = mapImg.width() / naturalWidth;
            mapRebuild( scaleValue );
        }, 500, 'resize-window');
    });

    function mapRebuild( scaleValue ) {
        var map = $("#imgMap");
        var mapareas = map.find( 'area' );
        if ( baseAreas.length == 0 ) {
            mapareas.each( function() {
                baseAreas.push( $(this).attr( 'coords' ) ); // set initial values
            });
        }
        mapareas.each( function( index ) {
            var coords = baseAreas[index]; // use the corresponding base coordinates        
            coords = coords.split( ',' );       
            var scaledCoords = '';
            for ( var coord in coords ) {
                scaledCoords += Math.floor( coords[coord] * scaleValue ) + ',';
            }
            scaledCoords = scaledCoords.slice( 0, -1 );
            $(this).attr( 'coords', scaledCoords );
        });
    }

    mapRebuild( scaleValue ); // initial scale

于 2013-12-04T06:13:15.093 に答える
0

ウィンドウがロードまたはサイズ変更されたときにイメージマップの座標を再計算するための具体的なサンプル:

この画像は 1930 * 3360 です:

  <div>
    <img id = "alhambra" src="filename.png" usemap="#image-map" width=100%>

    <map name="image-map">
        <area target="" alt="home" id = "home" title="home" href="" coords="1905,307,35,12" shape="rect">
        <area target="" alt="vaciado" id = "vaciado" title="vaciado" href="" coords="141,367,1783,631" shape="rect">
        <area target="" alt="tienda" id = "tienda" title="tienda" href="" coords="282,1408,278" shape="circle">
        <area target="" alt="stocks" id = "stocks" title="stocks" href="" coords="1300,2968,722,2699" shape="rect">
        <area target="" alt="whatsapp" id = "whatsapp" title="whatsapp" href="" coords="506,2980,1788,3193" shape="rect">
        <area target="" alt="direccion" id = "direccion" title="direccion" href="" coords="43,3215,1883,3324" shape="rect">
    </map>
  </div>

本文の後にスクリプトを次のように追加します。

</body>
<script>
  let text_home_coord = document.getElementById('home').coords;
  let text_vaciado_coord = document.getElementById('vaciado').coords;
  let text_tienda_coord = document.getElementById('tienda').coords;
  let text_stocks_coord = document.getElementById('stocks').coords;
  let text_whatsapp_coord = document.getElementById('whatsapp').coords;
  let text_direccion_coord = document.getElementById('direccion').coords;
  
  function img_map_response(){

    // get width and height in pixel
  var width_100_in_px = document.getElementById('alhambra').offsetWidth;
  var height_100_in_px = document.getElementById('alhambra').offsetHeight;

  // recalculate coords of image map
  function get_coor_resp(nombre_coords){

    // real width and height of image map
    var img_real_width="1930";
    var img_real_height="3360";

    // convert string coords to array
    text_array = nombre_coords.split(',');

    // rect
    if (text_array.length == 4) {
      // convert strig to integer
      x1 = parseInt(parseInt(text_array[0])*parseInt(width_100_in_px)/parseInt(img_real_width));
      y1 = parseInt(parseInt(text_array[1])*parseInt(height_100_in_px)/parseInt(img_real_height));
      x2 = parseInt(parseInt(text_array[2])*parseInt(width_100_in_px)/parseInt(img_real_width));
      y2 = parseInt(parseInt(text_array[3])*parseInt(height_100_in_px)/parseInt(img_real_height));
      // result converted in array of strings
      array_txt =[x1.toString(), y1.toString(), x2.toString(), y2.toString()]
      console.log("array_txt",array_txt)
      return array_txt.join(',')

    // circle
    } else {
      // convert strig to integer
      x1 = parseInt(parseInt(text_array[0])*parseInt(width_100_in_px)/parseInt(img_real_width));
      y1 = parseInt(parseInt(text_array[1])*parseInt(height_100_in_px)/parseInt(img_real_height));
      r = parseInt(parseInt(text_array[2])*parseInt(width_100_in_px)/parseInt(img_real_width));
      // result converted in array of strings
      array_txt =[x1.toString(), y1.toString(), r.toString()]
      return array_txt.join(',')        
    }
  }
  
 // set coords by recalculate coords (converted in string)
  document.getElementById('home').coords=get_coor_resp(text_home_coord);
  document.getElementById('vaciado').coords=get_coor_resp(text_vaciado_coord);
  document.getElementById('tienda').coords=get_coor_resp(text_tienda_coord);
  document.getElementById('stocks').coords=get_coor_resp(text_stocks_coord);
  document.getElementById('whatsapp').coords=get_coor_resp(text_whatsapp_coord);
  document.getElementById('direccion').coords=get_coor_resp(text_direccion_coord);
}
// add events load and resize for recalculate coords
window.addEventListener('load', img_map_response);
window.addEventListener('resize', img_map_response);
</script>

</html>
于 2021-11-06T20:09:03.053 に答える
-1

If you only need to resize the image, use this technique: http://www.cssplay.co.uk/layouts/background.html

Thanks to CSSPlay.

于 2009-12-02T16:05:03.463 に答える
-1

ウィンドウのサイズが変更されたときに関数を呼び出すには、次のことを試してください。

$(window).bind('resize', function() {
    // resize the button here
});

また、37 行目にドル記号がありません。

scaleXY('theMap',(window).width());

そのはず:

scaleXY('theMap',$(window).width());
于 2009-11-30T19:05:19.447 に答える