Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 向下滚动iFrame-jQuery/JS_Javascript_Jquery_Html_Iframe_Scroll - Fatal编程技术网

Javascript 向下滚动iFrame-jQuery/JS

Javascript 向下滚动iFrame-jQuery/JS,javascript,jquery,html,iframe,scroll,Javascript,Jquery,Html,Iframe,Scroll,我正试图通过点击一个不在iFrame中的按钮来滚动iFrame,我还不太了解Javascript/jQuery,我正在学习,也许有人可以在这里帮助我? 我将更具体地说,单击图像(如代码中所示,从imgcast1到imgcast4),iFrame将滚动到某个点,如果打开iFrame src,您可以看到iFrame内容,如果您想查看整个网站,但有很多bug,请在此处打开: (很多Adsense都是因为XPG而没有在Chrome中打开,至少在我的PC中没有) 以下是完整的代码: //IFRAM

我正试图通过点击一个不在iFrame中的按钮来滚动iFrame,我还不太了解Javascript/jQuery,我正在学习,也许有人可以在这里帮助我? 我将更具体地说,单击图像(如代码中所示,从imgcast1到imgcast4),iFrame将滚动到某个点,如果打开iFrame src,您可以看到iFrame内容,如果您想查看整个网站,但有很多bug,请在此处打开:
(很多Adsense都是因为XPG而没有在Chrome中打开,至少在我的PC中没有)

以下是完整的代码:


//IFRAME将滚动到440PX,然后是880PX(始终+440PX)。。。
-


$(文档).ready(函数(){
警报(“测试jQuery:已加载并执行”);
$('#imgcast1')。单击(函数(){
//滚动FOWN FUNC
});
// ---------------------------------------------
$('#imgcast2')。单击(函数(){
//滚动FOWN FUNC
});
// ---------------------------------------------
$('#imgcast3')。单击(函数(){
//滚动FOWN FUNC
});
// ---------------------------------------------     
$('#imgcast4')。单击(函数(){
//滚动FOWN FUNC
});
});
查看其他帖子的答案

仅供参考:他的jsbin代码由于一个未捕获的安全错误而无法正常工作,我已经修复了它,以便您可以看到代码正常工作

TL;博士


您可以通过div
“#iframeautcast”
而不是
滚动。由于跨域策略,操作
要困难得多,基本上您可以使用
.contents()
访问其中的任何内容。但这并不总是有效,我以前有过一些问题,我在你的问题中尝试过,但不知怎么的,它不起作用

var iframe = $('#iFrameAutocast frame').contents();
iframe.scrollTop(880);
另一种解决方案是使用
的父级
'#iframeautcast'
滚动:

$(document).ready(function () {

var by = 440;//scroll increment
/* base on your markup structure and what you are trying to achieve 
   you can trim it down using .each() and scrolling by an increment
*/
$('tr td img').each(function (index) {
    $(this).click(function () {
        $('#iFrameAutocast').scrollTop(by * index)
        //or with some animation:
        //$('#iFrameAutocast').animate({scrollTop:by * index},'slow');
    });
});

});

请参阅此JSFIDLE更新:

工作正常!谢谢但是你介意告诉我现在如何隐藏滚动条吗?哦,没关系!我把溢出-y:隐藏;而不是自动和工作!没问题,对于水平和垂直滚动,只需
溢出:隐藏。请接受我的回答,谢谢
<script>
$(document).ready(function (){
    alert("Testing jQuery: Loaded and Executed");
    $('#imgcast1').click(function() {
        //SCROLL FOWN FUNC
    });
// ---------------------------------------------
    $('#imgcast2').click(function() {
        //SCROLL FOWN FUNC
    });
// ---------------------------------------------
    $('#imgcast3').click(function() {
        //SCROLL FOWN FUNC
    });
// ---------------------------------------------     
    $('#imgcast4').click(function() {
        //SCROLL FOWN FUNC
    });

});
</script>
var myIframe = document.getElementById('iframe');
myIframe.onload = function () {
    myIframe.contentWindow.scrollTo(xcoord,ycoord);
}
var iframe = $('#iFrameAutocast frame').contents();
iframe.scrollTop(880);
$(document).ready(function () {

var by = 440;//scroll increment
/* base on your markup structure and what you are trying to achieve 
   you can trim it down using .each() and scrolling by an increment
*/
$('tr td img').each(function (index) {
    $(this).click(function () {
        $('#iFrameAutocast').scrollTop(by * index)
        //or with some animation:
        //$('#iFrameAutocast').animate({scrollTop:by * index},'slow');
    });
});

});