I’m asking because I don’t know much.
By any chance, is it possible to control the scroll position with Y px(pixel)?
I know it’s controlled with ‘CSS’ etc.
By any chance, is it possible to control the scroll position with ‘p5’?
You would need to put the return false; back so the wheel event is not passed onto the web browser. You would then need to add your own code to scroll the ‘document’. This should be possible through the DOM (Document Object Module) interface but I have little experience to doing that so perhaps someone else can take this discussion further.
Just curious, how did you get the scroll bars in your original post?
I’m not sure I understand the question being asked. In the following demo the y value controls the image position. If you want to change the image’s position in the window then change the y value.
let cat;
let y = -700; // This controls image position
function setup() {
createCanvas(windowWidth, windowHeight);
}
function preload(){
cat = loadImage('cat.png');
}
function draw() {
background(220);
image(cat,0,y);
}
function mouseWheel(event) {
if (event.delta > 0) {
console.log("mouseWheel up: +"+event.delta);
y += 10;
} else {
console.log("mouseWheel down: "+event.delta);
y -= 10;
}
}
Normally, scroll is controlled through ‘mouse wheel’.
If ‘return false;’ is used, scroll control is not possible through ‘wheel’.
I want to control ‘scroll position’ through ‘p5’. Scroll refers to the size of the entire ‘canvas’.
function setup() {
createCanvas(500, 5000);
}
function draw() {
background(220);
}
function mouseWheel(event) {
if (event.delta > 0) {
console.log("mouseWheel up: +"+event.delta);
// → Send to the top of the scroll
} else {
console.log("mouseWheel down: "+event.delta);
// → Send to the bottom of the scroll
}
}
1.) Your post title states that you want to control ‘scroll’ through mouseWheel.
2.) Now you state that you want to disable the mouseWheel.
3.) Scrolling won’t change the size of the canvas.
4.) If you want to change the viewPort with code that’s a different question.
The following may or may not be helpful depending on what you are trying to do:
// https://www.quirksmode.org/mobile/viewports.html
function setup() {
createCanvas(400, 2400);
console.log("window inner height = " + window.innerHeight);
console.log("pageYOffset pre-scroll = " + window.pageYOffset);
// REM out the next line to see what it does
window.scrollTo(0, 2300);
console.log("pageYOffset post-scroll= " + window.pageYOffset);
}
function draw() {
background(220);
circle(100, 2000, 100);
}
It is not practical to use the mouse wheel method to send’ to the top or to the bottom.
If you return false then the event is consumed and the browser never sees it so you can’t use the wheel to scroll to intermediate views. If you return true you have the same problem because the browser cannot scroll further than your method has already sent it. In both cases the only way to see intermediate views would be to drag the vertical scrollbar.