[英]How to make auto smooth scroll using js
I would like to auto scroll my page using js. 我想使用js自动滚动页面。 Example page with big image: 具有大图像的示例页面:
<html>
<body>
<IMG SRC="some_image.jpg" ALT="some text">
</body>
</html>
I found here how to do it but I don't understand how to use it. 我在这里找到了如何做,但我不知道如何使用它。
Could some one write me how to use that function? 有人可以写信给我如何使用该功能吗?
function pageScroll() {
window.scrollBy(0,1);
scrolldelay = setTimeout('pageScroll()',10);
}
I understand it must be betwen tags but I guess thats not enought 我了解它必须在标签之间,但我想那还不够
ok small edit: 好的小修改:
I found something like this and it works 我发现这样的东西,它的工作原理
<script src="jquery.js"></script>
<script>
$(document).ready(function () {
setInterval(function () {
var iScroll = $(window).scrollTop();
iScroll = iScroll + 200;
$('html, body').animate({
scrollTop: iScroll
}, 1000);
}, 2000);
});
</script>
The problem is I have to scroll my content which is in iframe How to modify this? 问题是我必须滚动iframe中的内容。如何进行修改?
edit2: 编辑2:
I change my code as you said now it looks like this: 正如您所说,我更改了代码,如下所示:
<html>
<body>
<script src="jquery.js"></script>
<script>
$(document).ready(function () {
setInterval(function () {
var iScroll = $("myframe")[0].conetentWindow.scrollTop;
iScroll = iScroll + 200;
$('html, body', parent.document).animate({
scrollTop: iScroll
}, 1000);
}, 2000);
});
document.write('<iframe src="http://link_to_image/image.jpg" name="myframe" height="50%" width="50%"></iframe>')
</script>
</body>
</html>
But it doesn't scroll my frame :/ 但是它不会滚动我的框架:/
The problem is I have to scroll my content which is in iframe 问题是我必须滚动iframe中的内容
$(document).ready(function () {
setInterval(function () {
var iScroll = $("#myIframe")[0].conetentWindow.scrollTop;
iScroll = iScroll + 200;
$('html, body', parent.document).animate({
scrollTop: iScroll
}, 1000);
}, 2000);
});
After talking to the OP - the iframe is on another doamin ( his control) 与OP通话后-iframe位于另一个doamin(由他控制)
so this is one of the solutions : 所以这是解决方案之一:
http://jsbin.com/UyAqIkUF/2/edit http://jsbin.com/UyAqIkUF/2/edit
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.