[英]How to make auto smooth scroll using js
我想使用js自動滾動頁面。 具有大圖像的示例頁面:
<html>
<body>
<IMG SRC="some_image.jpg" ALT="some text">
</body>
</html>
有人可以寫信給我如何使用該功能嗎?
function pageScroll() {
window.scrollBy(0,1);
scrolldelay = setTimeout('pageScroll()',10);
}
我了解它必須在標簽之間,但我想那還不夠
好的小修改:
我發現這樣的東西,它的工作原理
<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>
問題是我必須滾動iframe中的內容。如何進行修改?
編輯2:
正如您所說,我更改了代碼,如下所示:
<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>
但是它不會滾動我的框架:/
問題是我必須滾動iframe中的內容
$(document).ready(function () {
setInterval(function () {
var iScroll = $("#myIframe")[0].conetentWindow.scrollTop;
iScroll = iScroll + 200;
$('html, body', parent.document).animate({
scrollTop: iScroll
}, 1000);
}, 2000);
});
與OP通話后-iframe位於另一個doamin(由他控制)
所以這是解決方案之一:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.