如何使用Javascript使div可滚动

问题描述:


我正在开发Tizen并制作网络应用。

我在html5中有一个div,我在这个div上设置和图像作为背景。现在我有一些场景,我必须多次在这个div中显示一些随机文本。无法保证文本的大小始终相同。我的图像尺寸为300宽度和90高度。

I have a div in html5 and I set and image as background on this div. Now i have some scenario in which I have to show some random text in this div multiple times. It is no guaranteed that text always be the same size. My image size is 300 width and 90 height.

现在我想在文字较大时通过javascript在上下方向设置div滚动。我试过scrollTop,溢出:自动/滚动,但它无法正常工作。

Now I want to set my div scroll in up and down direction through javascript whenever my text is larger. I tried scrollTop, overflow: auto/scroll but its not working.

实际上我可以在eclipse中看到HTML视图的结果但是当我在设备上运行我的代码时它没有显示任何滚动条。任何帮助将不胜感激。

Actually I can see result on HTML view in eclipse but when I run my code on device its not showing any scrollbars. Any help would be appreciated .


这是我的代码,其中我有一个名为textView的div:

Here is my code in which I have a div named textView:



  <div id="textView" style="height: 90px; width: 300px;  
    margin-left: 20px; margin-top: 20px;overflow: auto;">
  </div>




在javascript中:

And in javascript:



  var elem = document.getElementById("textView");

  elem.scrollTop="80px";

  elem.innerHTML="llllllllllllllllllllllllllllllllllllllllll"+'<br/>'
  +"llllllllllllllllllllllllllllllllllllllllllll"+'<br/>'
  +"llllllllllllllllllllllllllllllllllllllllllll"+'</br>'
  +"llllllllllllllllllllllllllllllllllllllllllll"+'<br/>';
  elem.style.color = "White";

  elem.style.fontSize = "50px";




我想在图像范围内显示不超出图像范围的文本。

I want to show text in image bounds not out of bounds of image.


我相信你将它设为溢出的滚动:滚动应该照顾它。

I believe id you style it to overflow:scroll that should take care of it.

编辑:

看看设置 overflow-x:隐藏 overflow-y:auto

YET另一个编辑:
也许这个: https://developer.tizen.org/help/index.jsp?topic=%2Forg.tizen.web.appprogramming%2Fhtml%2Fguide%2Fui_guide%2Fui_framework_scrollview.htm

YET ANOTHER Perhaps this: https://developer.tizen.org/help/index.jsp?topic=%2Forg.tizen.web.appprogramming%2Fhtml%2Fguide%2Fui_guide%2Fui_framework_scrollview.htm