cubiq / iscroll

Smooth scrolling for the web
http://iscrolljs.com
MIT License
12.87k stars 3.81k forks source link

scrollToElement:Center in horizontal scroll not working. #1187

Open inJonathan opened 7 years ago

inJonathan commented 7 years ago

I want to center element to screen. I do this myScroll.scrollToElement(document.querySelector('#scroller li:nth-child(25)'), null, null, true) it's working in vertical scroll but not working in horizontal scroll.

TotooriaHyperion commented 7 years ago

if you are using iscroll 5, the param is (el, time, offsetX, offsetY, easing) you apparently set offsetX to null and offsetY to true thus, your final offset will be offsetX=0 offsetY=center. which means your target will be at center on y axis and at left side on x axis. according to https://github.com/cubiq/iscroll/blob/master/src/core.js#L508

inJonathan commented 7 years ago

@TotooriaHyperion 谢谢,我试试