0

I would like to auto scroll my page using 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?

edit2:

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 :/

Community
  • 1
  • 1
s1c
  • 159
  • 2
  • 11

1 Answers1

0

The problem is I have to scroll my content which is in 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)

so this is one of the solutions :

http://jsbin.com/UyAqIkUF/2/edit

Royi Namir
  • 144,742
  • 138
  • 468
  • 792
  • I change it but it doesn't work. I updated my question. Can you look at the code now? – s1c Nov 25 '13 at 12:15
  • @s1c - is the iframe src is in the same domain ? or is it from other domain ? – Royi Namir Nov 25 '13 at 12:26
  • so - it's not possible in convential means. but there is a hack. 5 min. – Royi Namir Nov 25 '13 at 12:34
  • Address of my script in the network is: web1.lan there is a index.html file with this code. On my second machine I have different content which I want to display and scrol. So the source is like this: web2.lan/site_with_content.html – s1c Nov 25 '13 at 12:43
  • @s1c you can use the codument.domain in both domains in order to break the SOP limitations , or you can use the hash trick as in my solution ( if you have control over the code in the other domain of course) – Royi Namir Nov 25 '13 at 12:44
  • Oh I have a one more question. What do I have to change if I want to scroll website instead of picture? – s1c Nov 25 '13 at 12:48
  • @s1c my code is not scrolling a picture. it is scrolling the whole html,body ( or window). it's just that my whole html is a long tall img . that's all – Royi Namir Nov 25 '13 at 12:49
  • But when I place my url in iframe it's not working anymore :( My picture is displayed on the website using img tag, so when I navigate to web2.lan its displayed. (its added to index file). – s1c Nov 25 '13 at 12:57
  • @s1c sorry i dont understand. can you supply printscreens ? – Royi Namir Nov 25 '13 at 13:03
  • Ok I will explain in details: I have 2 computers in local network. Both running apache. Addres for the first one is: web1.lan Here in index.html file where I have placed iframe in it. This website displas other page which is located on second server. This page contain some big picture. Address for this page is web2.lan so when I point my browser on web1.lan I can see content from my web2.lan Now I would like to auto scroll that content. – s1c Nov 25 '13 at 13:10