I may have overcome these instabilities in the Wix lightbox–but since it has been intermittent, I may be editing this again. I’ve put the solution in a comment.
The following code launches a light box with retrieved data for non-logged-in users and then MOST of the time prevents the lighbox from being launched multiple times when scrolling up and down or revisiting the specific dynamic page, where the page path is a unique identifier.
Can someone explain why the lightbox would display a second time when the visitor SCROLLS BACK UP? The lightbox never displays more than twice with repeated up-and-down scrolls. How can the occasional second display when scrolling up be prevented?
Thanks,
Doug
onviewportenter is triggered any time the element comes into view so I would guess that it’s something about your token code as from what I"m reading if that portion is working correctly the lightbox would not trigger.
I would try to debug that area and see what brake is returning each time the viewport code is triggered
@amandam Thanks, I already have done extensive logging, which I embedded in my question–the problem is that the memory storage set after the openLightbox, is not “sticking.” It (getItem) logs as set right after the setItem, but on scrolling back up into the viewWindow, the getItem then is read as null, so the lightbox redeploys. I now suspect that the Wix automatic closing of the lightbox is interfering with the storage setItem. I’m going to substitute my own onClick event to close the lightbox and see if that avoids this instability in the Wix lightbox functionality. (There is another problem with the lightbox that I hope also to avoid – closing the lightbox can often cause the screen to shoot back to the top of the page; very disruptive and also results in the lightbox opening again when scrolling back down.)
@amandam --It does appear that conflicts can occur between Wix lightbox and a storage item set when the lightbox is opened. What seems to have overcome this is to set the storage item inside the lightbox by passing the item value from the page to the lightbox. When the lightbox is closed, the storage value now remains in place, preventing the unwanted reopening of the lightbox. When only set in the page after opening the lightbox (as shown in the above code), the storage value was being “lost” so that the lightbox would reopen when scrolling back into the viewport . This also appears, so far, to eliminate the jumping of the viewport to the top of the page when the lightbox is closed. [I also substituted a close button with onClick event in the lightbox, replacing the Wix autogenerated closing button. But I’m not sure that is part of the solution.]