# Bug on slider not detaching from mouse and keeps attached on mouse released

**URL:** <https://forum.babylonjs.com/t/bug-on-slider-not-detaching-from-mouse-and-keeps-attached-on-mouse-released/28507>\
**Category:** Questions\
**Created:** [March 17, 2022, 2:37pm UTC](https://forum.babylonjs.com/t/bug-on-slider-not-detaching-from-mouse-and-keeps-attached-on-mouse-released/28507 "2022-03-17T14:37:24Z")\
**Posts on this page:** 19\
**Page:** 1

<div class="post-metadata">

**Author:** ![Balaji\_K](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/balaji_k/32/21293_2.png) [@Balaji\_K](https://forum.babylonjs.com/u/Balaji_K)\
**Post date:** [March 17, 2022, 2:37pm UTC](https://forum.babylonjs.com/t/bug-on-slider-not-detaching-from-mouse-and-keeps-attached-on-mouse-released/28507/1 "2022-03-17T14:37:25Z")

</div>

Hi All,

When I play with slider and release the button I see the slider is still attached to mouse and moving mouse in the screen keeps moving the slider left and right. Please note this doesn’t happen always but most of the time I am able to recreate this. Any help on am I missing something ?.

rgds  
Kamal

---

<div class="post-metadata">

**Author:** ![mawa](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/mawa/32/12384_2.png) [@mawa](https://forum.babylonjs.com/u/mawa)\
**Post date:** [March 17, 2022, 3:24pm UTC](https://forum.babylonjs.com/t/bug-on-slider-not-detaching-from-mouse-and-keeps-attached-on-mouse-released/28507/2 "2022-03-17T15:24:40Z")

</div>

Do you have a PG example? Are you using the bjs GUI? In case, do you use the slider inside a stackpanel? In case, I had something similar and would be able to help (may be)…

---

<div class="post-metadata">

**Author:** ![Balaji\_K](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/balaji_k/32/21293_2.png) [@Balaji\_K](https://forum.babylonjs.com/u/Balaji_K)\
**Post date:** [March 17, 2022, 4:30pm UTC](https://forum.babylonjs.com/t/bug-on-slider-not-detaching-from-mouse-and-keeps-attached-on-mouse-released/28507/3 "2022-03-17T16:30:31Z")

</div>

```auto
    var keys = [];
    var poanimation = new BABYLON.Animation("animation", "rotation.y", 30, BABYLON.Animation.ANIMATIONTYPE_FLOAT,
                          BABYLON.Animation.ANIMATIONLOOPMODE_CYCLE);
    var reanimation = new BABYLON.Animation("animation", "rotation.y", 30, BABYLON.Animation.ANIMATIONTYPE_FLOAT,
                          BABYLON.Animation.ANIMATIONLOOPMODE_CYCLE);
    var roanimation = new BABYLON.Animation("animation", "rotation.y", 30, BABYLON.Animation.ANIMATIONTYPE_FLOAT,
                          BABYLON.Animation.ANIMATIONLOOPMODE_CYCLE);

    // UI
    var advancedTexture = BABYLON.GUI.AdvancedDynamicTexture.CreateFullscreenUI("UI");
    var UiPanel = new BABYLON.GUI.StackPanel();
    UiPanel.width = "220px";
    UiPanel.fontSize = "14px";
    UiPanel.horizontalAlignment = BABYLON.GUI.Control.HORIZONTAL_ALIGNMENT_RIGHT;
    UiPanel.verticalAlignment = BABYLON.GUI.Control.VERTICAL_ALIGNMENT_TOP;
    advancedTexture.addControl(UiPanel);
    params = [
        {name: "vol", anim: poanimation},
        {name: "Rst", anim: reanimation},
        {name: "crs", anim: roanimation}
    ]
    params.forEach((param)=>{
        var header = new BABYLON.GUI.TextBlock();
        headers[param.name] = header;
        header.text = param.name;
        header.height = "40px";
        header.color = "white";
        header.textHorizontalAlignment = BABYLON.GUI.Control.HORIZONTAL_ALIGNMENT_LEFT;
        header.paddingTop = "10px";
        UiPanel.addControl(header); 
        var slider = new BABYLON.GUI.Slider();
        sliders[param.name] = slider;
        slider.horizontalAlignment = BABYLON.GUI.Control.VERTICAL_ALIGNMENT_TOP;
        slider.minimum = 0;
        slider.maximum = 1;
        slider.color = "yellow";
        slider.value = param.anim.weight;
        slider.height = "20px";
        slider.width = "200px";
        UiPanel.addControl(slider); 
        slider.onValueChangedObservable.add((v)=>{
            if (param.name == "vol") {
                particleSystem.ps = v;
            }
            if (param.name == "rst") {
                particleSystem.rs = v;
                sliderval.rs = v;
            }
            if (param.name == "crs") {
                sliderval.temp = v*20;
                if (v > 0) {
                    gcamera.alpha = v*20;
                }
            }
        }) 
        param.anim._slider = slider;
    });

```

Please find a a sample code above.

---

<div class="post-metadata">

**Author:** ![mawa](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/mawa/32/12384_2.png) [@mawa](https://forum.babylonjs.com/u/mawa)\
**Post date:** [March 17, 2022, 8:00pm UTC](https://forum.babylonjs.com/t/bug-on-slider-not-detaching-from-mouse-and-keeps-attached-on-mouse-released/28507/4 "2022-03-17T20:00:56Z")

</div>

Ok, but this code doesn’t really tell me the story. As you say,

> [@Balaji\_K](#):
>
> this doesn’t happen always

However, I believe I understand you must have the same case I had.  
I solved it by detaching the camera when moving on the slider and reattaching it when moving out.  
Try something like this (line 49 to 57 in this PG):

> **[Babylon.js Playground](https://playground.babylonjs.com/#NGS9AU%23453)**
>
> Babylon.js playground is a live editor for Babylon.js WebGL 3D scenes

Let us know if this helps,

---

<div class="post-metadata">

**Author:** ![Balaji\_K](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/balaji_k/32/21293_2.png) [@Balaji\_K](https://forum.babylonjs.com/u/Balaji_K)\
**Post date:** [March 18, 2022, 3:15pm UTC](https://forum.babylonjs.com/t/bug-on-slider-not-detaching-from-mouse-and-keeps-attached-on-mouse-released/28507/5 "2022-03-18T15:15:31Z")

</div>

@mawa it didn’t help Issue is when click in progress I take it out of window and bring it back in then this issue happens… Please note from logs I see no other event is detected.

---

<div class="post-metadata">

**Author:** ![mawa](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/mawa/32/12384_2.png) [@mawa](https://forum.babylonjs.com/u/mawa)\
**Post date:** [March 18, 2022, 3:57pm UTC](https://forum.babylonjs.com/t/bug-on-slider-not-detaching-from-mouse-and-keeps-attached-on-mouse-released/28507/6 "2022-03-18T15:57:23Z")

</div>

I see. Is it attached to the edge of the canvas and when you move out of the window the slider continues to be ‘grabed’ ?  
Did you try to add this?  
sv.isPointerBlocker = true;

or add a “window.addEventListener” for your canvas controls?

I’m pretty sure one of these should work and I’m also pretty sure there is already a thread in the forum that covers this. I will try find it for you…

---

<div class="post-metadata">

**Author:** ![Balaji\_K](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/balaji_k/32/21293_2.png) [@Balaji\_K](https://forum.babylonjs.com/u/Balaji_K)\
**Post date:** [March 18, 2022, 6:03pm UTC](https://forum.babylonjs.com/t/bug-on-slider-not-detaching-from-mouse-and-keeps-attached-on-mouse-released/28507/7 "2022-03-18T18:03:45Z")

</div>

@mawa Tried both the options but still do miss it once in a while…

---

<div class="post-metadata">

**Author:** ![sebavan](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/sebavan/32/57_2.png) [@sebavan](https://forum.babylonjs.com/u/sebavan)\
**Post date:** [March 18, 2022, 11:06pm UTC](https://forum.babylonjs.com/t/bug-on-slider-not-detaching-from-mouse-and-keeps-attached-on-mouse-released/28507/8 "2022-03-18T23:06:32Z")

</div>

cc @DarraghBurke

---

<div class="post-metadata">

**Author:** ![DarraghBurke](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/darraghburke/32/10621_2.png) [@DarraghBurke](https://forum.babylonjs.com/u/DarraghBurke)\
**Post date:** [March 18, 2022, 11:52pm UTC](https://forum.babylonjs.com/t/bug-on-slider-not-detaching-from-mouse-and-keeps-attached-on-mouse-released/28507/9 "2022-03-18T23:52:12Z")

</div>

I think this should fix your issue:

```auto
    scene.getEngine().onCanvasPointerOutObservable.add(() => {
        slider._forcePointerUp();
    })

```

Let me know if it doesn’t.

---

<div class="post-metadata">

**Author:** ![Balaji\_K](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/balaji_k/32/21293_2.png) [@Balaji\_K](https://forum.babylonjs.com/u/Balaji_K)\
**Post date:** [March 19, 2022, 5:22am UTC](https://forum.babylonjs.com/t/bug-on-slider-not-detaching-from-mouse-and-keeps-attached-on-mouse-released/28507/10 "2022-03-19T05:22:20Z")

</div>

@DarraghBurke when I hold click and move outside release click and come back in still its stuck, now if I take it out without holding click then it gets released.

---

<div class="post-metadata">

**Author:** ![mawa](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/mawa/32/12384_2.png) [@mawa](https://forum.babylonjs.com/u/mawa)\
**Post date:** [March 19, 2022, 2:47pm UTC](https://forum.babylonjs.com/t/bug-on-slider-not-detaching-from-mouse-and-keeps-attached-on-mouse-released/28507/11 "2022-03-19T14:47:32Z")

</div>

That’s funny because it never happened to me (and I’m actually unable to reproduce).  
Are any of these events/solutions we gave you appearing in the console log when you make your move?  
See, my sliders mostly always have an ‘exclusion zone’ so you can never move the mouse straight from the slider area outside the canvas. Also, did you try to remove the parameters for your contextual slider? May be the bug occurs because it’s loosing context?

I sure do hope either @DarraghBurke or @sebavan will be able to further help here. I’m afraid this is slowly going beyond my expertise.

Wishing you a great WE anyway and don’t loose hope 😉 I’m sure someone in this forum will be able to finally help you out with this 😌

---

<div class="post-metadata">

**Author:** ![sebavan](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/sebavan/32/57_2.png) [@sebavan](https://forum.babylonjs.com/u/sebavan)\
**Post date:** [March 20, 2022, 7:48pm UTC](https://forum.babylonjs.com/t/bug-on-slider-not-detaching-from-mouse-and-keeps-attached-on-mouse-released/28507/12 "2022-03-20T19:48:37Z")

</div>

Assigned @DarraghBurke on March 20, 2022, 7:48pm UTC



---

<div class="post-metadata">

**Author:** ![DarraghBurke](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/darraghburke/32/10621_2.png) [@DarraghBurke](https://forum.babylonjs.com/u/DarraghBurke)\
**Post date:** [March 21, 2022, 5:04pm UTC](https://forum.babylonjs.com/t/bug-on-slider-not-detaching-from-mouse-and-keeps-attached-on-mouse-released/28507/13 "2022-03-21T17:04:59Z")

</div>

What browser/device are you on? I do not repro this on Edge for Windows or MacOS. Here is the playground I am testing with, based off the one Mawa shared earlier:

[GUI Example | Babylon.js Playground (babylonjs.com)](https://playground.babylonjs.com/#NGS9AU#454)

---

<div class="post-metadata">

**Author:** ![Balaji\_K](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/balaji_k/32/21293_2.png) [@Balaji\_K](https://forum.babylonjs.com/u/Balaji_K)\
**Post date:** [March 27, 2022, 12:01am UTC](https://forum.babylonjs.com/t/bug-on-slider-not-detaching-from-mouse-and-keeps-attached-on-mouse-released/28507/14 "2022-03-27T00:01:03Z")

</div>

@DarraghBurke After some more testing have some observation…

> > Add HTML to iframe this issues is seen  
> > As a seperate HTML page this issue isn’t seen.

rgds  
Kamal

---

<div class="post-metadata">

**Author:** ![mawa](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/mawa/32/12384_2.png) [@mawa](https://forum.babylonjs.com/u/mawa)\
**Post date:** [March 27, 2022, 11:48am UTC](https://forum.babylonjs.com/t/bug-on-slider-not-detaching-from-mouse-and-keeps-attached-on-mouse-released/28507/15 "2022-03-27T11:48:40Z")

</div>

Now, that’s interesting. Obviously, the iframe already acts like a ‘canvas’ (well, a frame). So this can explain why any action calling on the ‘window’ would actually not apply to the iframe.  
Did you try the thing of creating a small exclusion zone around the slider, to make sure any action taken triggers (within BJS) and before you move out of (well) the iframe? As long as the action triggers inside the canvas before moving out of the window or iframe, it definetely should work and solve your issue.

---

<div class="post-metadata">

**Author:** ![DarraghBurke](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/darraghburke/32/10621_2.png) [@DarraghBurke](https://forum.babylonjs.com/u/DarraghBurke)\
**Post date:** [March 28, 2022, 4:26pm UTC](https://forum.babylonjs.com/t/bug-on-slider-not-detaching-from-mouse-and-keeps-attached-on-mouse-released/28507/16 "2022-03-28T16:26:40Z")

</div>

You might try listening to a “blur” event on either `contentDocument` or `contentWindow` of the IFrame: [HTML DOM IFrame Objects (w3schools.com)](https://www.w3schools.com/jsref/dom_obj_frame.asp)

---

<div class="post-metadata">

**Author:** ![DarraghBurke](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/darraghburke/32/10621_2.png) [@DarraghBurke](https://forum.babylonjs.com/u/DarraghBurke)\
**Post date:** [April 5, 2022, 6:43pm UTC](https://forum.babylonjs.com/t/bug-on-slider-not-detaching-from-mouse-and-keeps-attached-on-mouse-released/28507/17 "2022-04-05T18:43:50Z")

</div>

Any luck getting this to work?

---

<div class="post-metadata">

**Author:** ![DarraghBurke](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/darraghburke/32/10621_2.png) [@DarraghBurke](https://forum.babylonjs.com/u/DarraghBurke)\
**Post date:** [April 7, 2022, 8:10pm UTC](https://forum.babylonjs.com/t/bug-on-slider-not-detaching-from-mouse-and-keeps-attached-on-mouse-released/28507/18 "2022-04-07T20:10:27Z")

</div>

Unassigned @DarraghBurke on April 7, 2022, 8:10pm UTC



---

<div class="post-metadata">

**Author:** ![Balaji\_K](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/balaji_k/32/21293_2.png) [@Balaji\_K](https://forum.babylonjs.com/u/Balaji_K)\
**Post date:** [April 21, 2022, 12:32am UTC](https://forum.babylonjs.com/t/bug-on-slider-not-detaching-from-mouse-and-keeps-attached-on-mouse-released/28507/19 "2022-04-21T00:32:24Z")

</div>

@DarraghBurke Sorry for the delay was traveling. Since it was near the edge this was happening I gave a padding from the edge and now this issue is not there.
