Open rodneyrehm opened 10 years ago
this already slipped under my radar. I believe the best solution is to threat the "refresh" (and "init") events as special events and pass them directly as init parameters in the options object.
beforeRefresh
wouldn't be a problem.
So this is a planned enhancement @cubiq ?
Hey Matteo,
By using plain CSS I can give a list of elements the full width of the page while making them appear in line. Essentially horizontally scrolling elements that each have the dimension of the viewport. iScroll will only make that scrollable when I calculate the effective width of all the scrollElement's children and apply that to scrollElement. This by itself is not a problem. It can be done rather easily:
This looks generic enough to be included in iScroll's
snap
module. (Caution,Element.children
andElement.firstElementChild
aren't supported by oldIE).My real quarrel is with reacting to changing viewports, though. If I register an event handler for
refresh
, it is run after IScroll-internal handlers have been executed. So right now I have no choice but listen to window.onresize myself:As you can see I forgot to also listen to
orientationchange
and I didn't debounce my event handling. It works, but it's an ugly solution that leaves me - the developer - open to making silly mistakes. I would much prefer one of the following solutions:resize
that is triggered before the refresh happens. It's good enough for me, but will fail the next guy, cause it's not triggered for a manual call toscroller.refresh()
, which I'd have done after adding a new item to the list (i.e. modified the scrolling content).beforeRefresh
that is triggered as the very first thing ofrefresh()
. Your events are executed synchronously and thus allow me to fix things externally, every time IScroll updates its stuff internally.dimensions
that accepts a callback function that allows me to configure calculating width and height:I think I would go with option 2 and 3. 2 allows the most flexibility for anything I haven't thought of yet, 3 solves the problem of calculating dimensions.