开发者

With javascript, how to you get the browser to make sure one part of the page is displayed?

have a DIV with a scroll bar on the page. trying to ensure a particular item is visible to the user.

the DIV itself is always contained i开发者_如何学JAVAn the visible area of the page, and the page never has a scrollbar itself.

for example, the DIV might have 8 paragraphs, and I want to make sure in certain situations that the user can see paragraph 5 within the DIV right now.


You could use an anchor tag by the paragraph you want to be visible, whenever the situation arises where you want to be sure that this section is visible you can link to the anchor through javascript. Example follows

Create an anchor by the desired paragraph

<a name="FOO"></a>

The javascript to move to your anchor

<script type="text/javascript" language="javascript">
    function moveToAnchor ()
{
window.location.hash="FOO";
}
</script>

What remains is to call this script when you desire. you could do it with an onload in the body tag or through some other means you feel appropriate

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜