开发者

Scroll DIV Horizontally with Mouse Events

I have a layout as follows:

<div style="width: 300">
  开发者_运维知识库  <div style="width: 300">Some Content</div>
</div

I want to be able to mousedown in the content DIV and be able to move it left to right, or scroll it in other words :)

What would be the best way of being this?

I would prefer it in JavaScript mainly :)


Easiest would be to use Mootools or jQuery. Both have "drag" interfaces to handle this sort of thing, and handle all the cross-browser compatibility problems.

If you're fixed on rolling your own, then the basic process is to attach mousedown/mouseup events on the parent div to initiate the dragging stuff, slap a handler on mousemove to capture the motion events, and adjust the parent div's scroll offsets as appropriate.


Better add css to your div

div id {
width:300px;
height:300px;
overflow:scroll;
}

and write the JQuery or javascript you want to do.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜