|
阅读:6825回复:4
FF,iframe的scrollTo问题
想通过点击按钮,使页面中的iframe包含的news.htm网页滚动,但是在非IE下效果不能实现,可能&FF对scrollTo或者scroll解释有关,尝试了n次,还是未搞定,网上也没有找到合适的代码,大虾指点一下。
可以直接浏览[url=http://www.dancewithnet.com/temp1/index.htm]http://www.dancewithnet.com/temp1/index.htm[/url] <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-Strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<style type="text/css">
<!--
body{text-align:center}
div{border:1px solid #000;margin:0 auto;width:300px}
iframe{width:300px;height:300px}
span{color:#c0c0c0}
-->
</style>
<script type="text/javascript">
//<![CDATA[
function mov(a){
news=window.news
scrollx=news.document.body.scrollLeft?news.document.body.scrollLeft:news.document.documentElement.scrollLeft;
scrolly=news.document.body.scrollTop?news.document.body.scrollTop:news.document.documentElement.scrollTop;
scrolly+=a;
news.window.scrollTo(scrollx,scrolly);
}
function movstar(a,time){ movx=setInterval("mov("+a+")",time)}
function movover(){clearInterval(movx)}
//]]>
</script>
</head>
<body>
<div>
<iframe id="news" name="news" src="news.htm" scrolling="no"></iframe>
<a onmouseup="movover();movstar(-1,20)" onmousedown="movover();movstar(-3,2)" onmouseover="movstar(-1,20);"
onmouseout="movover()" title="向上滚动...按住将滚动得更快">&&</a> <span>--按住将滚动更快--</span><a onmouseup="movover();movstar(1,20)" onmousedown="movover();movstar(3,2)" onmouseover="movstar(1,20)"
onmouseout="movover()" title="向下滚动...按住将滚动得更快" >&&</a>
</div>
</body>
</html>
谢谢。 |
|
|
|
1楼#
发布于:2005-08-04 17:41
不懂,楼下
|
|
|
2楼#
发布于:2005-08-04 17:41
楼下还在等楼下来解决阿。
|
|
|
|
3楼#
发布于:2005-08-04 17:41
function mov(a){
if (document.getElementById){
news = document.getElementById("news");
}
else{
eval('news = "news";');
}
if (news.contentDocument){
//ns6 syntax
scrollx=news.contentWindow.pageXOffset;
scrolly=news.contentWindow.pageYOffset;
scrolly+=a;
news.contentWindow.scrollTo(scrollx,scrolly);
}
else if (news.document){
//ie5+ syntax
scrollx=news.document.body.scrollLeft?news.document.body.scrollLeft:news.document.documentElement.scrollLeft;
scrolly=news.document.body.scrollTop?news.document.body.scrollTop:news.document.documentElement.scrollTop;
scrolly+=a;
news.window.scrollTo(scrollx,scrolly);
}
}
代替原来的mov函数 这是由于Firefox与IE之间DOM的不同造成的,所以要分别为两个浏览器编写不同的代码 这个我是比较讨厌的。还好不是很麻烦 |
|
|
4楼#
发布于:2005-08-04 17:41
非常的棒,谢谢楼上,我要好好研究研究。
javascript,html dom,xmldom,中ie&ff的确有非常多的不同,我目前没有找到这方面很好的资料,只好一边学一边做了,楼上有这方面的资料不?谢谢 |
|
|