简体   繁体   English

jQuery Mousewheel问题

[英]Jquery Mousewheel issue

I am using a svg map, where I want to be able to zoom in/out and pan around. 我正在使用svg地图,我希望能够在其中放大/缩小和平移地图。 Using the mousewheel plugin but getting an error: 使用mousewheel插件但出现错误:

Error: Invalid value for <svg> attribute viewBox="NaN NaN NaN NaN"

So the zoom is not working correctly, please have a look at my example: 因此缩放无法正常工作,请看一下我的示例:

http://jsfiddle.net/41sz0068/14/ http://jsfiddle.net/41sz0068/14/

I am using Mapael: 我正在使用Mapael:

$(".container").mapael({
    map : {
        name : "my_map"
        , zoom : {
            enabled : true,
            maxLevel : 10
        }
    }
});

As specified in the comments, this happens because some value is not initialized accordingly, and you get an error when using the mousewheel. 如注释中所指定的,发生这种情况是因为未相应初始化某些值,并且在使用鼠标滚轮时会出错。 It doesn't happen if you have previously used the zoom In/zoom Out features. 如果您以前使用过放大/缩小功能,则不会发生这种情况。

One possible workaround: trigger the zoom out function on page load. 一种可能的解决方法:在页面加载时触发缩小功能。 As the image will start always without zoom, zooming out will not affect the svg and it will initialize whichever variables were not initialized at the beginning: 由于图片始终会在不缩放的情况下开始,因此缩小不会影响svg,并且会初始化开始时未初始化的变量:

$(function() {
    $("div.zoomOut").click();
});

You can see it on your JSFiddle: http://jsfiddle.net/41sz0068/15/ 您可以在您的JSFiddle上看到它: http : //jsfiddle.net/41sz0068/15/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM