代码之家  ›  专栏  ›  技术社区  ›  michael reas

移动设备上的完整背景图像,通过拖动查看端口在整个图像周围移动

  •  0
  • michael reas  · 技术社区  · 7 年前

    我有一张地图的图像 enter image description here

    在手机上,我想被带到地图的一个特定部分(比如非洲),然后通过捏来绕着整个地图移动。

    我的CSS在这里:

    main {
      background-image: url("map.jpg");
      /* Full height */
      height: 100vh; 
      /* Center and scale the image nicely */
      background-position: center;
      background-repeat: no-repeat;
      background-size: cover;
    }
    

    然而,在手机上,我发现: enter image description here

    我捏不动地图。我该怎么做?

    你可以 simulate 通过按住shift键并单击鼠标,在Chrome上的视图端口上拖动。

    确保在devtools上的mobile view上进行测试。

    2 回复  |  直到 7 年前
        1
  •  0
  •   lalit bhakuni    7 年前

    我觉得你需要 java script 用于移动背景img

    我已经找到了解决办法。

    **感谢@banzomaikaka** Using Mouse Drag To Control Background Position

    演示 http://jsfiddle.net/VRvUB/854/

        2
  •  0
  •   SakoBu    7 年前

    您需要在HTML文件的头部使用此元标记: 尝试以下操作:

    <meta name="viewport" content="width=device-width, initial-scale=.5, maximum-scale=12.0, minimum-scale=.25, user-scalable=yes"/>