弄清楚了。这是后代的代码:
$('#map').bind('mousewheel DOMMouseScroll', function(e){
//Get the transformation matrix from the css as a string. (it's named differently for different browsers)
var scale = $(this).css('transform');
scale = (scale == null ? $(this).css('-webkit-transform') : scale);
scale = (scale == null ? $(this).css('-ms-transform') : scale);
//once we have the matrix, the scale is the first number, so parse the string to remove it.
scale = scale.split(" ");
scale = parseFloat(scale[0].substring(7, scale[0].length - 1));
//e.originalEvent tells us how the mousewheel moves. (Also different for different systems)
e.delta = null;
if (e.originalEvent) {
if (e.originalEvent.wheelDelta) e.delta = e.originalEvent.wheelDelta / -40;
if (e.originalEvent.deltaY) e.delta = e.originalEvent.deltaY;
if (e.originalEvent.detail) e.delta = e.originalEvent.detail;
}
//If delta is greater than 0, we're zooming in
if(e.delta > 0) {
//5x zoom is the max that I want to zoom in.
if(scale < 5) {
//no need to re-form the matrix. specifying a new scale value will do the job.
scale = ('scale(' + (scale + .1).toString() + ')');
//update the transform css for each possible browser.
$(this).css({'transform':scale, '-ms-transform':scale, '-webkit-transform':scale });
}
}
//if delta is less than zero, we're zooming out
else{
//for my purposes, I don't want to zoom out farther than the original map size
if(scale > 1) {
scale = ('scale(' + (scale - .1).toString() + ')');
$(this).css({'transform':scale, '-ms-transform':scale, '-webkit-transform':scale });
}
}