如何通过拖动而不是使用滚动条来滚动 div
我正在开发一个使用触摸屏界面的项目。我在一个较小的 div 内有一个 div,因此较小的 div 有滚动条来访问第一个 div 的其余部分。这是它的基本代码。
.div1{
height: 100px;
width: 100px;
}
.div2{
height: 50px;
width: 50px;
}
html 是:
<div id = "div2" class="div2">
<div id="div1" class="div1"></div>
</div>
使用 javascript,我希望能够通过按下(因为它是触摸屏)屏幕的未占用部分并沿 div 拖动来滚动 div2。基本上,滚动功能的行为方式与谷歌地图在您单击并拖动时的行为方式相同。有人能帮我解决这个问题吗?提前致谢!
注意
就鼠标操作而言,按下相当于单击此处,只是为了清楚起见。我也只在 Firefox 中工作,所以跨浏览器兼容性不是问题。
I am working on a project that uses a touch-screen interface. I have a div inside of a smaller div, so the smaller div has scroll bars to access the rest of the first div. Here is the basic code for it.
.div1{
height: 100px;
width: 100px;
}
.div2{
height: 50px;
width: 50px;
}
and the html is:
<div id = "div2" class="div2">
<div id="div1" class="div1"></div>
</div>
Using javascript, I would like to be able to scroll through div2 by pressing (since it is a touch screen) an unoccupied part of the screen and dragging along the div. Basically, the scroll feature would behave the way google maps does when you click and drag in it. Can anybody help me with this? Thanks in advance!
Note
In terms of mouse actions, pressing is equivalent to clicking here, just to be clear. I am also working in Firefox only, so cross-browser compatibility is not an issue.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这有效...在你引用 FireFox 之前我就开始为移动 Safari 制作它...所以它可能有一些额外的...
This works...I'd started making it for mobile safari before you cited FireFox...so it may have a little extra...
我发现了这个不错的 JQuery 插件(不确定您是否可以使用 JQuery)
http://digitalillusion.altervista.org/wordpress/pages/dragscroller/viewport-test.html
I found this nice JQuery plugin (Not sure if you are ok with using JQuery or not)
http://digitalillusion.altervista.org/wordpress/pages/dragscroller/viewport-test.html