admin管理员组文章数量:1366332
I'm using a shadowbox which generates an iframe to display product details on a page. Because the details page can be pretty long, the client would like a "More" button that scrolls the page down (apparently the scrollbar on the right of the iframe isn't enough).
Here's the code that I've tried in order to get the iframe to scroll:
$(document).ready(function()
{
$(".moreButton img").click(function() {
scrollbottom();
});
});
function scrollbottom() {
var x = 250; // this number is a temporary placeholder
var t = 500;
$("iframe").animate({ scrollTop: x }, t);
}
I've also tried using body instead of iframe but to no avail. Any ideas? Thanks!
I'm using a shadowbox which generates an iframe to display product details on a page. Because the details page can be pretty long, the client would like a "More" button that scrolls the page down (apparently the scrollbar on the right of the iframe isn't enough).
Here's the code that I've tried in order to get the iframe to scroll:
$(document).ready(function()
{
$(".moreButton img").click(function() {
scrollbottom();
});
});
function scrollbottom() {
var x = 250; // this number is a temporary placeholder
var t = 500;
$("iframe").animate({ scrollTop: x }, t);
}
I've also tried using body instead of iframe but to no avail. Any ideas? Thanks!
Share Improve this question asked May 18, 2010 at 15:34 Chris StahlChris Stahl 1,8123 gold badges15 silver badges17 bronze badges 04 Answers
Reset to default 3Like this: (Tested)
$("iframe").contents().children().animate({ scrollTop: x }, t);
Create a function in the parent javascript like this:
function scrollToPoint(top) {
$("html, body").animate({ scrollTop: top }, "slow")
}
and call that function within the iframe like this:
window.parent.scrollToPoint(top);
It should work in chrome, not tested in firefox yet
This ended up working:
$('html,body').animate({ scrollTop: x }, t);
In Chrome I had to specifically select the body element:
$('#my-iframe').contents().find('body').animate({scrollTop:90},500);
本文标签: javascriptHow do you scroll an iframe from within using jqueryStack Overflow
版权声明:本文标题:javascript - How do you scroll an iframe from within using jquery? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743778625a2537440.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论