How can开发者_运维问答 you scroll through the viewport of a DIV? I need to build a horizontal scrolling feature on my site where the user has left and right arrows. I've never build anything like this and am wondering how this is done?
If scrollbars wont be a problem for what you're doing, then alex's solution will work best. However, if you don't want scrollbars, you can try to nest a div inside the viewport div, and move the inside div to the coordinates you need. By setting the viewport div's overflow to hidden, you can effectively hide the content that is not seen through the viewport.
Unfortunately, you will need to know the width of your content to be able to do this.
You can adjust the scrollLeft
property.
$('div').attr('scrollLeft', 500);
精彩评论