Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

draggable backgroun

I want to achieve something like an infinite drag like the one in Konva js Can anyone help me with this. I try varius things but non of them were ok. Im new in p5js and javascript. Please for any hints. Only this element prevents me from completing the entire project.

var grid;
var current_img;
var BgCat1 = [];
var layerOne;
let show_grid = false;

like image 717
Michael Avatar asked Nov 16 '19 14:11

Michael


People also ask

How do I make an image draggable?

To make an object draggable set draggable=true on that element. Just about anything can be drag-enabled: images, files, links, files, or any markup on your page.

What does draggable do in HTML?

The draggable global attribute is an enumerated attribute that indicates whether the element can be dragged, either with native browser behavior or the HTML Drag and Drop API.

Can a div be draggable?

Btw, you can make a div "draggable" without JS, but you cannot "drag" it.

How do I make a picture not draggable?

Setting the draggable HTML Attribute to false We can also set the draggable HTML attribute of the img element we want to disable dragging for to false . to disable dragging. To do the same thing with JavaScript, we can use the setAttribute method: const img = document.

How to use jQuery draggable ()?

This is done by clicking on the object to be dragged using mouse and dragging it anywhere within the view port. This feature of jQueryUI is helpful in adding interaction animations to the web pages to make them more powerful and interactive. This is a guide to jQuery draggable ().

Is it possible to make an element draggable around the screen?

Just to be clear, even when we pull this off in HTML and CSS, all we’re getting done is making the element draggable around the screen. If you actually need to do something as a result of that dragging, your back in JavaScript territory. This trick comes by way of Scott Kellum.

How to create a draggable div element?

Create a Draggable DIV Element 1 Step 1) Add HTML:#N#Example#N#<!-- Draggable DIV -->#N#<div id="mydiv">#N#<!-- Include a header DIV with the same name as the... 2 Step 2) Add CSS:#N#The only important style is position: absolute, the rest is up to you:#N#Example#N# 3 mydiv {#N#position:... 4 Step 3) Add JavaScript: More ...

What is draggablescrollablesheet widget in flutter?

In this tutorial, we are going to learn what the DraggableScrollableSheet widget is and how to implement it in Flutter. Flutter is an open-source UI software development kit created by Google with which we can develop applications for Android, IOS, Desktop, and Web with a single codebase.


1 Answers

There may be a more elegant solution, but here I draw an extra cell on each side of the grid to handle the wraparound, so a 12x12 grid with 10x10 visible. See it run here: https://editor.p5js.org/rednoyz/full/uJCADfZXv

let dim = 10, sz;
let xoff = 0, yoff = 0;

function setup() {
  createCanvas(400, 400);
  sz = width/ dim;
}

function mouseDragged() {
  xoff += mouseX - pmouseX;
  yoff += mouseY - pmouseY;
}

function draw() {
  background(255);

  for (let i = 0; i < dim+2; i++) {
    for (let j = 0; j < dim+2; j++) {

      let x = ((xoff + j * sz) % (width+sz)) - sz;
      if (x < -sz) x += width+sz;

      let y = ((yoff + i * sz) % (height+sz)) - sz;
      if (y < -sz) y += height+sz;

      rect(x, y, sz, sz);
      text(i * 10 + j, x + sz/2, y + sz/2);
    }
  }
}
like image 69
rednoyz Avatar answered Sep 21 '22 19:09

rednoyz