How to control touchpad scroll in a carousel component - javascript

I am working on a carousel component where elements change on an up and down scroll. When you're scrolling with your mouse everything works pretty nicely but the touchpad scroll sometimes scrolls the elements all the way to the end. The component can be viewed here: https://2r70m7.csb.app/. Is it possible to somehow control a single touchpad scroll, so that no matter how intense it is, it can only move a single element in the carousel?
Thanks

Related

How to change css styles on scroll without delay

Hi everyone,
I'm working on a side navigation menu for my churches website. You can see the demo here:
http://amightywind.com/sideNav/
However I have a problem. The navigation is supposed to work so when you scroll down the page past it's bottom the css changes to make it anchor and stop moving.
The problem is that the "anchoring" effect doesn't always work smoothly and will only be applied after you scrolled a few pixels past the bottom.
This causes the side bar to "jump" back into it's designed place.
I know this problem is probably caused by asynchronous panning (the browser delays repainting when scrolling to keep a smooth frame rate).
I was going to call this unsolvable, but then I saw firefox's quantum browser page.
If you scroll down halfway, you will see a large pink box on the left that says "Firefox Quantum features".
The text changes positioning when you scroll into it similarly to how my side bar works. However 2 things are different.
1 there is no jump. It is perfectly smooth in every browser I tested.
I figured this could easily be because they are moving a smaller portion of content than I am, but....
2 when I inspect element I notice there is no css class/style change on the object when scrolled into it.
How is this possible? Is there a way to make this effect work without Javascript? Or at least more smoothly than I've done just listening to the window scroll event?
Any help would be much appreciated thank you!

Preventing horizontal scrolling on mobile (HTML/CSS/JS)

I'm putting the finishing touches on this parallax website but I'm having trouble preventing some very unattractive horizontal scrolling effects (try it yourself on a touch device by dragging directly to the left).
I've adapted the parallax technique described here using 3D CSS transforms. Unfortunately, one of the side-effects seems to be that the browser thinks the images are wider than the viewport, even though they aren't. I've already tried:
Adding overflow-x: hidden; to the parallax images' containing div, and while that's hidden the horizontal scrollbar, it alone does not actually prevent horizontal scrolling.
Adding a partial workaround scroll event listener to reset the scrollLeft of the container back to 0 with each scroll, which solves the problem entirely on desktop (AFAICT) and partly on mobile (at least when scrolling diagonally).
Unfortunately, it seems that, at least on Android (I don't have an iPhone to test) it's still possible to scroll horizontally without triggering the scroll event workaround. Even more mystifying, while it's in this weird horizontally-scrolled mode I've programmatically traversed the entire DOM and not a single element has a scrollLeft property != 0. I've also called $('*').scrollLeft(0); from the console and it doesn't reset the scrolling. Now calling .preventDefault() on all touchmove events does prevent the horizontal scrolling, but it also effectively breaks the site as a whole since it prevents vertical scrolling too--so that's a no-go.
So how is this thing scrolling horizontally if nothing has a scrollLeft other than 0, and how can I prevent/workaround this scrolling behavior?

diagonal parallax with scrollto nav

I'm trying to create a site that has a parallax type effect with scrollTo navigation control.
Similar to http://www.nike.com/jumpman23/aj2012/ however I only need to scroll on left and right (up & down). I can do horizontal and vertical parallax, and scrollTo I just cant get the diagonal parallax working (with mouse scroll)
I've currently got it working using scrollTo however this disables the user being able to scroll with the mouse. I'm creating a dynamic one page site so some times a pages content may be longer then other areas so the user will need to scroll down, once they reach the end of this content the parallax effect kicks in.
Can anyone suggest a way to do this? Or point me in the right direction.

Scrolling a div vertically using buttons

I'm building a mobile app using HTML, CSS, Javascript and jQuery.
Is there a way to scroll a div that is longer (700px) than the mobile screen (480px) using only two buttons, one for down and one for up?
So when a user presses and holds the down button it appears to scroll down the div by about 10px at a time.
Edit:
The mobile app is actually being compiled with Phonegap, so it won't be a mobile website but an actual application.
The application features dragging and dropping quite heavily and in order to do this using JQuery and HTML, I've had to bind the mousedown, mouseup and mousehover events to touch events.
Because of this the user cannot simply drag the screen to scroll as they would a typical application. Therefore, I have decided to go with physical buttons instead of scrolling the navigation div.
The navigation div is set to have a greater height than the canvas (screen height and width) div. This will be the div the user is scrolling.
Is the div you're talking about scrolling the full page itself? Or is it a specific div that you want to "scroll" within the page (kind of like an iframe)?
Both can be done. If you're scrolling the full page, I'm not sure why you'd want to use buttons rather than let Safari simply handle the standard swipe gestures. But, it could be done this way:
Use fixed positioning on the buttons so that they don't move as the rest of the screen scrolls.
Use use jQuery's .scrollTop method to do the scrolling.
If, on the other hand, you want to make a scroll effect on a single div, without the rest of the page scrolling, then just do the following:
Wrap that div in another div that has overflow:hidden; position:relative
Make the inner div position:absolute
Animate the inner div's top property to create the scrolling effect.
You may find this plugin useful: http://logicbox.net/jquery/simplyscroll/vertical.html
Anyway, why would you need that? The user may be able to scroll normally with a finger swipe if the content is bigger than the screen.

Javascript: don't stop scrolling window if the cursor passes over a scrollable div

I'm building a web app that has a grid of many small scrollable divs (actually, Ace editors), and this grid has enough elements that it is larger than the window. When a user begins scrolling over empty space, I want them to be scrolling the window itself; when a user begins scrolling inside a grid element, I want them to scroll the div contents there. The thing is, if a user begins scrolling over empty space, and then scrolls such that their mouse goes over a grid element, that scrollable div captures all the scrolling events, interrupting the user's flow over the grid and "trapping" them inside the grid element.
I can't manually capture onmousewheel events, since AFAIK there's no way to capture horizontal mouse wheel movement separately from vertical, and I want users on Mac OS X to be able to scroll in all directions. I've thought about using JS to add an invisible div with a very high z-index on the first onscroll event, and removing it as soon as onscroll events aren't triggered for a certain period of time. Haven't yet coded this up, but I'm wondering if there's a better solution, or if there are any potential pitfalls that I haven't thought of. Any help or advice would be great! Thanks!
I think a solution for this would be incredibly difficult due to browser support, and the actual solution, which would probably be something like calculating the scroll, backtracking the div, and applying the scroll to the page.
You could do something like this:
$('div').scroll(function(e){
// figure out how much it has scrolled
window.scrollBy(0,howmuch);
});
I don't recommend this solution in the slightest though, I think the better option would be to set the divs to overflow:hidden; and pick up a solid scroll plugin, and use that to customize the scroll behavior on the divs.

Categories