开发者

jquery iframe scroll

开发者 https://www.devze.com 2023-01-17 02:44 出处:网络
I have an iframe in my page and i want to create 开发者_StackOverflow社区a button that when i press it the page in the iframe scrolls down...

I have an iframe in my page and i want to create 开发者_StackOverflow社区a button that when i press it the page in the iframe scrolls down...

Can anyone help?


  $("#scrolldownbut").click(function()
  { 
      var q=$("#theframe").scrollTop();

      q=q+100;
      $("#theframe").scrollTop(q);

      return false;  
  });

This code works fore me. The frame's id and name is theframe and the scrollbut is a div to scroll down the frame. Notice: the frames width and height must not be in percentage (thats what i wanted to do) because in percentage it doesnt work.


I believe this article answers it better than I ever would - http://flesler.blogspot.com/2007/10/jqueryscrollto.html

Let me elaborate:

I've used flesler's library before for the same purpose(scrolling an iFrame inside a facebook application, same deal more or less) and it's honestly beautiful. The linked article explains several detailed situations in how you'd use scrollTo, and it works nicely.


You can scroll an iFrame using Javascript with the scrollTo and scrollBy methods. This has been discussed here before, and the answer there has a simple example:

How to Scroll an iFrame using javascript


To use flesler, you can do

<div id="pane-target" class="pane">
  <iframe style="width:1000px; height:1000px" src="MyInformation.html"></iframe>
</div>
0

精彩评论

暂无评论...
验证码 换一张
取 消