I am trying to create a Leaflet menu based on the properties of the Layer Control code of Leaflet. This menu becomes automatically scrollable if it is greater than the space left between the top of menu and the bottom of the map.
Javascript:
var acceptableHeight = this._map._size.y - (this._container.offsetTop + 60);
if (this._form.clientHeight > acceptableHeight) {
this._form.style.height = acceptableHeight + 'px';
L.DomUtil.addClass(this._form, 'menu-scrollbar');
}
else {
L.DomUtil.removeClass(this._form, 'menu-scrollbar');
}
CSS:
.menu-scrollbar {
overflow-y: auto;
padding-right: 10px;
}
The scroll bar is perfectly created depending on the size of the form, but it always moves to the top when the mouse cursor goes out of the scrolling bar zone (that is the line which the bar follows). Something also strange is that the bar stays on the same place only if the mouse is quickly changing its cursor type (such as when located on an HTML input zone).
An image can be better than a long explanation: screenshot of the menu.
I've been looking around similar problems with the scrolling bar:
But the answers are not exactly related to the same issue, and I would like to use pure JavaScript rather than mix it with jQuery. One of the feasible solution could be to get the scroll bar position (how to get it) and set it manually (how to do it).
But I am sure that this problem comes from something else tht i don't get. Can someone help me with this ?
Fiddle example: http://jsfiddle.net/LnzN2/1121/
Thank you in advance.