The idea is : if the image (can i retrieve image viewport current height ?) is >50 % of the viewport height, scroll to image after 5000 ms, else do nothing
import wixWindow from 'wix-window';
wixWindow.getBoundingRect()
.then( (windowSizeInfo) => {
let windowHeight = windowSizeInfo.window.height; // 565
let windowWidth = windowSizeInfo.window.width; // 1269
let documentHeight = windowSizeInfo.document.height; // 780
let documentWidth = windowSizeInfo.document.width; // 1269
let scrollX = windowSizeInfo.scroll.x; // 0
let scrollY = windowSizeInfo.scroll.y; // 120
} );
So what do you need to get the size of your image?
And which command you could use to achieve your aim?
This looks good… (i think). This should give you back the current “scrol-position”.
let scrollX = windowSizeInfo.scroll.x; // 0
let scrollY = windowSizeInfo.scroll.y; // 120
That means!
If you do a SCROLL and you would be able to make an EVENT, caused by an element ----> for example —> onViewPortEnter??? and onViewPortOut???
What do you think, could this work for you ?
Pseudo-Code: (while you are scrolling your page in which you have some PICs)
@russian-dima Hello ! Yeah i know what you mean there ! You pointed that well, i have 2 problems :
Retreiving the image percentage in the viewport height (Less than 50 %)
Yes i can retrieve the height of the image, or the height of the viewport, but not the image height in viewport with that
Making an event handler understanding : when the user stop scrolling, go to the previous or next image, considering its viewport height
Viewportenter ? How about the user continue scolling ? even not on the viewport anymore, he will be brought back, and it will make a loop of scrolling (made that mistake already)
Is visible ? well, it’s always visible, even not on the viewport
SetTimeout ? Yes, but if i want to cancel the action because the user left the image, it will send him back anyway
@russian-dima Hello Russia, i know what i need : the scroll event, because i can retrieve the Document height and the window height. So to scroll to one or another, it can’t be on viewport, but only on scroll stop (then set a timer that handle an event doing “if the client stop for 3 sec, scroll to …”), i’ll try to build a (hazardous) method with the scroll X,Y , will keep you updated
@edouard
At moment i do not have the time to support you more (working on own projects), just can show you some existing examples. You will have to do the rest on your own, sorry.
@russian-dima Well, that was already awesome from you, you did help me out a lot here, and in other posts ! When i first saw your message, i was hyped af ^^
Thanks for your time, i’ll post a updated code snippet if i figure it out and help the community with it !
ok here i my code, it’s based on viewport, it almost work but there is like an up and down movement when your between 2 viewport ! Maybe i should use clearTimeout with another viewportleave…
var myvar
//scrolls to features
export function toPur_viewportEnter() {
$w("#imageX1").scrollTo()
clearTimeout(myvar)
}
export function toPur_viewportLeave(event) {
myvar = setTimeout(() => { $w("#imageX1").scrollTo()}, 3000 )
}
export function toHarmonie_viewportEnter() {
$w("#Harmonie").scrollTo();
clearTimeout(myvar)
}
export function toHarmonie_viewportLeave(event) {
myvar = setTimeout(() => { $w("#Harmonie").scrollTo()}, 3000 )
}
export function toElegance_viewportEnter() {
$w("#Elegance").scrollTo();
clearTimeout(myvar)
}
export function toElegance_viewportLeave(event) {
myvar = setTimeout(() => { $w("#Elegance").scrollTo()}, 3000 )
}
export function toLoft_viewportEnter() {
$w("#imageX3").scrollTo();
clearTimeout(myvar)
}
export function toLoft_viewportLeave(event) {
myvar = setTimeout(() => { $w("#imageX3").scrollTo()}, 3000 )
}
export function toScience_viewportEnter() {
$w("#imageX4").scrollTo();
clearTimeout(myvar)
}
export function toScience_viewportLeave(event) {
myvar = setTimeout(() => { $w("#imageX4").scrollTo()}, 3000 )
}
export function toBetonne_viewportEnter() {
$w("#Betonne").scrollTo();
clearTimeout(myvar)
}
export function toBetonne_viewportLeave(event) {
myvar = setTimeout(() => { $w("#Betonne").scrollTo()}, 3000 )
}
export function toWork_viewportEnter() {
$w("#imageX5").scrollTo();
clearTimeout(myvar)
}
export function toWork_viewportLeave(event) {
myvar = setTimeout(() => { $w("#imageX1").scrollTo()}, 3000 )
}
export function menu_viewportEnter(event) {
clearTimeout(myvar)
}