热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

当光标在右列上方时,如何滚动左列?-Howtoscrollleftcolumnwhencursorisaboverightcolumn?

HowtoscrollupanddowntheleftcolumnwhenImscrollingoverthemapcanvas?当我在地图画布上滚动时,如何上下滚动

How to scroll up and down the left column when I'm scrolling over the map canvas?

当我在地图画布上滚动时,如何上下滚动左列?

Map has disabled scroll wheel propagation, it would be nice to accomplish it if possible only by CSS. I've tried to wrap #map_canvas by other div with flex property and set map to position absolute and 100vh/vw, but it doesn't make difference with wheel bubble.

Map已经禁用了滚动轮传播,如果可能的话,最好只通过CSS来完成。我尝试过用flex属性将#map_canvas与其他div一起封装,并将map设置为绝对位置和100vh/vw,但这与轮泡没有区别。

$(document).ready(function() {
  var post = "

Post title

Donec id elit non mi porta gravida at eget metus. Maecenas sed diam eget risus varius blandit.

"; var i = 0; while (i <10) { $('#left_container').append(post); i++; } var optiOns= { zoom: 10, scrollwheel: false, center: new google.maps.LatLng(49, 17) }; var map = new google.maps.Map($('#map_canvas')[0], options); $("#map_canvas").scrollLeft(); });
.flexbox-container {
  display: -ms-flex;
  display: -webkit-flex;
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  height: 100vh;
}
.flexbox-container #left_container {
  flex: 1;
  padding: 0 5px;
  overflow-y: auto;
  height: 100vh;
}
#map_canvas {
  flex: 2;
}



2 个解决方案

#1


2  

jsfiddle

jsfiddle

In this solution, I am assuming map is 200px wide. You can replace it by another value in css and js.

在这个解中,我假设map是200px宽。您可以用css和js中的另一个值替换它。

You want to scroll the leftmost column when the mouse is hover the rightmost (map) column.
To accomplish this, the leftmost column should actually occupy all the viewport, although visually does not look like that.

当鼠标悬停在最右边(映射)列时,您希望滚动最左边的列。为了实现这一点,最左边的列实际上应该占据所有的viewport,尽管看起来不是这样的。

In the #left_container below, you can see that is absolutely placed to fit all .flexbox-container parent boundaries. The trick part is the border-right: 200px transparent solid that "pushes" the vertical scroll bar to the left.

在下面的#left_container中,您可以看到它完全适合所有的.flexbox-container父边界。关键在于右边框:200px透明实体,将垂直滚动条“推”到左边。

So, when you move your mouse wheel on the map, you are actually hovering the #left_container's right border and thus moving it up and down, not the map.

所以,当你在地图上移动鼠标滚轮时,你实际上是在#left_container的右边界上盘旋,从而上下移动它,而不是映射。

.flexbox-container {
  height: 90vh;
  position: relative;
}

#left_container {
  padding: 0 5px;
  overflow-y: auto;
  display: inline-block;
  height: 100%;
  border-right: 200px transparent solid;
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 1;
  pointer-events: none;
}

#left_container.scrollMap {
  pointer-events: auto;
}

#map_canvas {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: 200px;
}

The above CSS solution, completely ignores other maps events (dblclick, click,...)
To fix that, we need a bit of JS to ignore mouse events on the leftmost column (see pointer-events):

上面的CSS解决方案完全忽略了其他映射事件(dblclick, click,…)为了解决这个问题,我们需要一些JS来忽略最左侧列上的鼠标事件(参见指针事件):

  var map_canvas = $('#map_canvas')[0],
      $left_cOntainer= $('#left_container'),
      $parent = $('.flexbox-container'),
      optiOns= {
          zoom: 10,
          scrollwheel: false,
          center: new google.maps.LatLng(49, 17)
      },
      map = new google.maps.Map(map_canvas, options),
      wheelEvent = function (e) {
          $left_container.addClass('scrollMap');
      };

  map_canvas.addEventListener('mousewheel', wheelEvent);
  map_canvas.addEventListener('DOMMouseScroll', wheelEvent);
  $parent.mousemove(function (e) {
    if (e.clientX <$parent.width() - 200) {
      $left_container.addClass('scrollMap');
    } else {
      $left_container.removeClass('scrollMap');
    }    
  });


#2


1  

Here's a way to transfer the scroll event of a container #canvas_container to the left column by Javascript. To accomplish this, the map has to be inside a container and padded at the top and bottom (.padder elements).

这里有一种方法可以通过Javascript将容器#canvas_container的滚动事件转移到左侧列。要实现这一点,映射必须位于容器内,并在顶部和底部填充(。微调电容器元素)。

This way you can theoretically scroll up and down, catch this scroll event and transfer it to the left column. Other events are not touched.

这样,理论上可以上下滚动,捕获滚动事件并将其转移到左侧列。其他事件不会被触动。

The key part is this Javascript:

关键部分是Javascript:

  $canvas_cOntainer= $('#canvas_container')
  $left_cOntainer= $('#left_container');
  initial_offset = 100;

  $canvas_container.scrollTop(initial_offset);

  $canvas_container.on('scroll', function(e) {
    $left_container.scrollTop($left_container.scrollTop() + $canvas_container.scrollTop() - initial_offset);
    $canvas_container.scrollTop(initial_offset);
  });

Only drawback I see atm is the visible vertical scroll bar on the map.

我看到atm的唯一缺点是地图上可见的垂直滚动条。

To play around by yourself, see this fiddle.

要自己玩,看看这个小提琴。

$(document).ready(function() {
  var post = "

Post title

Donec id elit non mi porta gravida at eget metus. Maecenas sed diam eget risus varius blandit.

"; var i = 0; while (i <10) { $('#left_container').append(post); i++; } var optiOns= { zoom: 10, scrollwheel: false, center: new google.maps.LatLng(49, 17) }; var map = new google.maps.Map($('#map_canvas')[0], options); $canvas_cOntainer= $('#canvas_container') $left_cOntainer= $('#left_container'); initial_offset = 100; // same as height of .padder $canvas_container.scrollTop(initial_offset); $canvas_container.on('scroll', function(e) { $left_container.scrollTop($left_container.scrollTop() + $canvas_container.scrollTop() - initial_offset); $canvas_container.scrollTop(initial_offset); }); });
.flexbox-container {
  display: -ms-flex;
  display: -webkit-flex;
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  height: 80vh;
}
.flexbox-container #left_container {
  flex: 1;
  padding: 0 5px;
  overflow-y: auto;
  height: 80vh;
}
#canvas_container {
  flex: 2;
  height: 80vh;
  overflow-y: scroll;
}
#map_canvas {
  height: 100%;
}
.padder {
  height: 100px;
}




推荐阅读
  • 本文由编程笔记#小编为大家整理,主要介绍了css回到顶部按钮相关的知识,希望对你有一定的参考价值。 ... [详细]
  • 如何在HTML中获取鼠标的当前位置
    本文介绍了在HTML中获取鼠标当前位置的三种方法,分别是相对于屏幕的位置、相对于窗口的位置以及考虑了页面滚动因素的位置。通过这些方法可以准确获取鼠标的坐标信息。 ... [详细]
  • javascript  – 概述在Firefox上无法正常工作
    我试图提出一些自定义大纲,以达到一些Web可访问性建议.但我不能用Firefox制作.这就是它在Chrome上的外观:而那个图标实际上是一个锚点.在Firefox上,它只概述了整个 ... [详细]
  • Voicewo在线语音识别转换jQuery插件的特点和示例
    本文介绍了一款名为Voicewo的在线语音识别转换jQuery插件,该插件具有快速、架构、风格、扩展和兼容等特点,适合在互联网应用中使用。同时还提供了一个快速示例供开发人员参考。 ... [详细]
  • Html5-Canvas实现简易的抽奖转盘效果
    本文介绍了如何使用Html5和Canvas标签来实现简易的抽奖转盘效果,同时使用了jQueryRotate.js旋转插件。文章中给出了主要的html和css代码,并展示了实现的基本效果。 ... [详细]
  • Ihavethefollowingonhtml我在html上有以下内容<html><head><scriptsrc..3003_Tes ... [详细]
  • IjustinheritedsomewebpageswhichusesMooTools.IneverusedMooTools.NowIneedtoaddsomef ... [详细]
  • jQuery实现简单的动画效果及用法详解
    本文详细介绍了使用jQuery实现简单动画效果的方法,包括显示/隐藏、向上收缩/向下展开、淡入/淡出、自定义动画等。同时提供了具体的用法示例,并解释了参数的含义和使用技巧。通过本文的学习,读者可以掌握如何使用jQuery实现各种动画效果,为网页增添生动和互动性。 ... [详细]
  • 本文介绍了使用jQuery实现图片预加载和等比例缩放的方法,同时提供了演示和相关代码。该方法可以重置图片的宽度和高度,并使图片在水平和垂直方向上居中显示。 ... [详细]
  • 本文介绍了DataTables插件的官方网站以及其基本特点和使用方法,包括分页处理、数据过滤、数据排序、数据类型检测、列宽度自动适应、CSS定制样式、隐藏列等功能。同时还介绍了其易用性、可扩展性和灵活性,以及国际化和动态创建表格的功能。此外,还提供了参数初始化和延迟加载的示例代码。 ... [详细]
  • 本文介绍了如何使用vue-awesome-swiper组件,包括在main.js中引入和使用swiper和swiperSlide组件,以及设置options和ref属性。同时还介绍了如何在模板中使用swiper和swiperSlide组件,并展示了如何通过循环渲染swipes数组中的数据,并使用picUrl属性显示图片。最后还介绍了如何添加分页器。 ... [详细]
  • 本文介绍了Java后台Jsonp处理方法及其应用场景。首先解释了Jsonp是一个非官方的协议,它允许在服务器端通过Script tags返回至客户端,并通过javascript callback的形式实现跨域访问。然后介绍了JSON系统开发方法,它是一种面向数据结构的分析和设计方法,以活动为中心,将一连串的活动顺序组合成一个完整的工作进程。接着给出了一个客户端示例代码,使用了jQuery的ajax方法请求一个Jsonp数据。 ... [详细]
  • 本文介绍了如何在Jquery中通过元素的样式值获取元素,并将其赋值给一个变量。提供了5种解决方案供参考。 ... [详细]
  • 本文总结了在编写JS代码时,不同浏览器间的兼容性差异,并提供了相应的解决方法。其中包括阻止默认事件的代码示例和猎取兄弟节点的函数。这些方法可以帮助开发者在不同浏览器上实现一致的功能。 ... [详细]
  • mui框架offcanvas侧滑超出部分隐藏无法滚动如何解决
    web前端|js教程off-canvas,部分,超出web前端-js教程mui框架中off-canvas侧滑的一个缺点就是无法出现滚动条,因为它主要用途是设置类似于qq界面的那种格 ... [详细]
author-avatar
choojo深呼吸
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有