November 28, 2011

How to auto scroll down an iframe 100px every 5 secs?

Question by Kaoukkos

I would like to know how can I scroll down an iframe 100px every 5 secs using maybe javascript. I know that there is a window.scrollTo(x,y); but how does this change to an iframe?

The iframe is an external page.
Any possibility of software to download that does this thing?

Answer by Starx

Its very easy using a jquery,

Lets say the id of your iframe is testframe then the code for it would be

$("#testframe").scrollTop(400).scrollLeft(400);

Now just wrap it inside an interval and put it inside.

var tick=1;
function scrolldown(tick) {
    $("#testframe").scrollTop(tick*100);
}
self.setInterval("scrolldown("+(tick+1)+")",5000);

Note: Just a typo

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+

...

Please fill the form - I will response as fast as I can!