Javascript简单滑块:如何在mouseMove上取消活动拖动

Javascript简单滑块:如何在mouseMove上取消活动拖动,javascript,html,Javascript,Html,我正在用Javascript制作一个简单的滑块 首先,我创建一个DIV并附加一个表示滑块“空白”状态的图像。DIV对mousedown、mouseup和mousemove作出反应。每次启动mousedown时,事件侦听器都会设置为mousemove(根据鼠标坐标调整滑块),并且当启动mouseup时,事件侦听器会被删除 DIV中有另一个图像,与第一个图像重叠。它展开并表示滑块 问题是,当我点击DIV并开始移动鼠标时,它的反应就像希望我拖动某个东西。也许是图片(空白状态)。我看到“不能在这里降落”

我正在用Javascript制作一个简单的滑块

首先,我创建一个DIV并附加一个表示滑块“空白”状态的图像。DIV对mousedown、mouseup和mousemove作出反应。每次启动mousedown时,事件侦听器都会设置为mousemove(根据鼠标坐标调整滑块),并且当启动mouseup时,事件侦听器会被删除

DIV中有另一个图像,与第一个图像重叠。它展开并表示滑块

问题是,当我点击DIV并开始移动鼠标时,它的反应就像希望我拖动某个东西。也许是图片(空白状态)。我看到“不能在这里降落”的图标看起来像一个错误的方向标志

如何摆脱它?我可以粘贴滑块的一些方法,但它与问题不太相关


下面是滑块的完整代码:

volCont是容器DIV,volGauche是滑块的左端,volDroite是右侧,volMilieu是主空白图片,volPx是表示滑块的图片(最初为1像素宽,一直展开)

以下是滑动方法:

this.startSlide = function(event)
{
    var set_perc = (event.clientX - that.volCont.offsetLeft) / (that.volCont.offsetWidth);
    that.setSlide(set_perc);
    that.volCont.addEventListener('mousemove', that.moveSlide, false);
};

this.moveSlide = function(event)
{
    var set_perc = (event.clientX - that.volCont.offsetLeft) / (that.volCont.offsetWidth);
    that.setSlide(set_perc);
};

this.stopSlide = function(event)
{
    var set_perc = (event.clientX - that.volCont.offsetLeft) / (that.volCont.offsetWidth);
    that.setSlide(set_perc);
    that.volCont.removeEventListener('mousemove', that.moveSlide, false);
}

请为您的问题创建一个最小的示例-。如果没有代码,则无法进行故障排除。
this.startSlide = function(event)
{
    var set_perc = (event.clientX - that.volCont.offsetLeft) / (that.volCont.offsetWidth);
    that.setSlide(set_perc);
    that.volCont.addEventListener('mousemove', that.moveSlide, false);
};

this.moveSlide = function(event)
{
    var set_perc = (event.clientX - that.volCont.offsetLeft) / (that.volCont.offsetWidth);
    that.setSlide(set_perc);
};

this.stopSlide = function(event)
{
    var set_perc = (event.clientX - that.volCont.offsetLeft) / (that.volCont.offsetWidth);
    that.setSlide(set_perc);
    that.volCont.removeEventListener('mousemove', that.moveSlide, false);
}