在iframe中滚动位置 [英] Scroll position in an iframe

查看:319
本文介绍了在iframe中滚动位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我正在使用一个电子学习网站.这里有两个框架.在左侧页面中,正在加载所有目录的目录(标题,章节1,章节2 ---索引,书目-),内容将根据到目录.该功能运行正常

我想做的是,当我们更改Toc(例如,从ChapterI到ChapterV)时,滚动位置也会随之改变.
我们可以同时传递第I章"和第V章"的值,我们也不需要希望具有以下功能的函数
document.getElementById("frame_left").src =网址+#" +传递值


这是我们在左框架中放置内容的代码
----------------

Hi All,

I am working with an E-learning website.Here we have two frames .In a page on left side there is loading all TOC(Title,chapter1,chapter2---Index,Biblography--) on right side the content will display according to the TOC.The function is working perfectly

Here I want to do is when we change the Toc(Eg. chapterI to ChapterV)the scroll position also change according to that.
we can pass the value both ''chapter I'' and ''chapter V'' also we don'' want the function like the following one
document.getElementById("frame_left").src = Url + "#" + passingvalue


Here is our code for loding the content in left frame
----------------

var content = jsonCommon.GetTocHtml_Stream(sBookID, SessionID)//getting the content;
                   globalcontent = content;
                   var s = document.getElementById('frame_left');
                   s.contentDocument.write(_globalcontent );


-------------------------
在这里我得到了一些提示


-------------------------
Here I got some hint

myIframe.contentWindow.scrollTo(xcord, ycord)//chapter I to chapterV;


如何获得xcord和ycord或任何其他方法?

请帮我如何实现呢?


谢谢&问候,
soumya


how can I get the xcord and ycord or any other method?

Pls help me how can I implement this?


Thanks & regards,
soumya

推荐答案

可以找到元素的x和y

there is a way to find x and y of a element

var thepoint  = myfunc_GetXY(myIframe.contentWindow.document.getElementById("some_Element"));
myIframe.contentWindow.scrollTo(thepoint.x, thepoint.y)//chapter I to chapterV;

or use : 
myIframe.contentWindow.document.getElementById("some_Element").scrollIntoWiew()

function myfunc_GetXY(aTag)
{
    var oTmp = aTag;
    var pt = new Point(0, 0);
    do
    {
        pt.x += oTmp.offsetLeft;
        pt.y += oTmp.offsetTop;
        oTmp = oTmp.offsetParent;
    } while (oTmp && oTmp.tagName != "HTML" && oTmp.tagName != "BODY");
    return pt;
}



感谢您的回复
当我执行以下步骤时,它显示一个错误
未定义点

var pt = new Point(0,0);


请帮助
Hi,
Thanks for your response
when I come to the following step it''s showing one error
Point is not defined

var pt = new Point(0, 0);


pls help
Thanks & regards,
soumya


这篇关于在iframe中滚动位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆