question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Drag not working on example

See original GitHub issue

Hey, I noticed that in the example provided in the repo’s README dragging doesn’t work even though the viewport.drag() is being called, is it supposed to be like that? How could this code be modified to allow dragging?

import * as PIXI from 'pixi.js'
import { Viewport } from 'pixi-viewport'

const app = new PIXI.Application()
document.body.appendChild(app.view)

// create viewport
const viewport = new Viewport({
    screenWidth: window.innerWidth,
    screenHeight: window.innerHeight,
    worldWidth: 1000,
    worldHeight: 1000,

    interaction: app.renderer.plugins.interaction // the interaction module is important for wheel to work properly when renderer.view is placed or scaled
})

// add the viewport to the stage
app.stage.addChild(viewport)

// activate plugins
viewport
    .drag()
    .pinch()
    .wheel()
    .decelerate()

// add a red box
const sprite = viewport.addChild(new PIXI.Sprite(PIXI.Texture.WHITE))
sprite.tint = 0xff0000
sprite.width = sprite.height = 100
sprite.position.set(100, 100)

Thanks in advance.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
iosonosempreiocommented, Mar 4, 2020

Hi, I had the same issue in a project which combines ReactJS and PIXIjs.

The problem turned out to be related to a z-index set on the div that contains the canvas generated by PIXI. Once I removed the pan/drag got restored.

In my project, the code looked like this (the div in the render is where PIXIjs operates).

render() {
    const elmStyle = {
        width: "100vw",
        height: "100vh",
        position: "absolute",
        top: 0,

        // remove this
        🚨 zIndex: -10   
    };
    return <div id="pixi-js-inside-of-here" style={elmStyle} ref={this.init.bind(this)}></div>;
}

I figured it out because I remembered I had the same issue with a d3js generated SVG which I wanted to zoom and pan. To me this indicates the z-index property may generally affects pointer events behavior, probably in relation to which other elements are there in the page. However it looks weird to me that only the drag was broken, while the scroll-wheel zoom and the pinch zoom did not present any issues.

0reactions
davidfigcommented, Mar 4, 2020

Good find. The wheel uses a separate event that attaches to document (I think). So that makes sense. If you’re talking about the trackpad pinch then that also makes sense for the same reason. If you’re talking about the touchscreen pinch then I agree that does not make sense since it uses the same event listeners as the drag.

Read more comments on GitHub >

github_iconTop Results From Across the Web

basic drag and drop examples not working on rails
I'm reading the files on the client using javascript, get some info, and then make an ajax call. All that works when using...
Read more >
Drag and drop/click and drag stops working temporarily ...
Hello, I've been having this weird problem with the touchpad of my new HP Envy Windows 10 system. My ability to click-and-drag stops...
Read more >
File drag and drop - Web APIs | MDN
This example illustrates the use of both APIs (and does not use any Gecko specific interfaces). Define the drop zone. The target element...
Read more >
Click and Drag Not Working with Touchpad | Articles
But if using a touchpad, you may need a bit more finger-work. Click+drag (Example: scrollbars)¶. Click and hold the left touchpad button. Run...
Read more >
Drag'n'Drop with mouse events
In the examples above the ball is always moved so that its center is ... The problem is that, while we're dragging, the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found