我尝试将事件绑定到滑块按钮。
这是我的滑块按钮html:
<input id="swipe" type="range" style="width: 100%">
这里是Javascript函数,我尝试绑定事件:
function createMap() {
var swipe = document.getElementById('swipe');
var bing = new ol.layer.Tile({
source: new ol.source.BingMaps({
key: 'My Bing Map sKey',
imagerySet: 'Aerial'
})
});
bing.on('precompose', function (event) {
var ctx = event.context;
var width = ctx.canvas.width * (swipe.value / 100);
ctx.save();
ctx.beginPath();
ctx.rect(width, 0, ctx.canvas.width - width, ctx.canvas.height);
ctx.clip();
});
bing.on('postcompose', function (event) {
var ctx = event.context;
ctx.restore();
});
swipe.addEventListener('input', function () {
map.render();
}, false);
}
如上所示,每当我移动滑块时,都必须触发swipe.addEventListener
。
但是当我移动滑块时,swipe.addEventListener
不会触发,似乎没有添加事件。
知道为什么没有添加活动?以及如何解决它?
更新
每当我移动滑块时都会收到此警告:
The specified value "NaN" is not a valid number. The value must match to the following regular expression: -?(\d+|\d+\.\d+|\.\d+)([eE][-+]?\d+)?