scrollBy在Firefox和Opera中不起作用 [英] scrollBy doesn't work in Firefox and Opera
问题描述
此scrollBy函数可在Internet Explorer中使用,但在Firefox和Opera中将被忽略.谁能帮助解决这个问题?
This scrollBy function works in Internet Explorer, but ignores by Firefox and Opera. Can anyone help to solve this problem?
function scrollLeft(s){
document.frames['my_iframe'].scrollBy(-s,0);
window.frames['my_iframe'].scrollBy(-s,0);
}
function scrollRight(s){
document.frames['my_iframe'].scrollBy(s,0);
window.frames['my_iframe'].scrollBy(s,0);
}
以下是在Internet Explorer浏览器中可用但在Firefox和Opera中不可用的示例: http://igproject.ru/iframe-scrolling/index.htm
Here is an example that works in Internet Explorer browser, but doesn't work in Firefox and Opera: http://igproject.ru/iframe-scrolling/index.htm
推荐答案
在Firefox等中,您需要使用scrollTo()
而不是scrollBy()
.
In Firefox, etc. you need to use scrollTo()
instead of scrollBy()
.
请参阅: http://jsfiddle.net/4CkML/
示例:
window.scrollTo(50,50);
如果域不匹配,则不能使用scrollTo/By.您可以在此处看到javascript错误的产生:
You cannot use scrollTo/By if the domains don't match. You can see here that a javascript error is produced:
拒绝访问属性"scrollTo"的权限
Permission denied to access property 'scrollTo'
编辑-更新答案以合并较长评论链中的答案:
Edit - Updating answer to incorporate answer from long comment chain:
var oIF = document.getElementById('my_iframe').contentWindow; oIF.scrollBy(s, 0);
这篇关于scrollBy在Firefox和Opera中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!