简体   繁体   English

在iframe中使用iScroll

[英]Using iScroll in iframe

All 所有

I want to use iScroll in iframe. 我想在iframe中使用iScroll

This is my code 这是我的代码

HTML HTML

<form>
        <input type="text" class="frmUrlVal">
        <input type="submit" class="frmSubmit" value="Go">
      </form>
      <iframe src="http://www.css-tricks.com" width="360" height="500" id="dynFrame"></iframe>

JS JS

$(function()
{
  $('.frmSubmit').click(function(e)
  {
    $('#dynFrame').attr('src', $('.frmUrlVal').attr('value'));
    e.preventDefault();
  });
});

This is my jsfiddle link : http://jsfiddle.net/ajaypatel_aj/JtCJa/​ ​You can see here there is vertical scrollbar, i want to use iSroll instead of that regular scroller. 这是我的jsfiddle链接: http//jsfiddle.net/ajaypatel_aj/JtCJa/你可以看到这里有垂直滚动条,我想使用iSroll而不是常规滚动条。 I tried with applying the id but it not work for me. 我尝试使用id,但它对我不起作用。

Thanks In Advance ! 提前致谢 !

我认为你最接近的选择是http://jsfiddle.net/JtCJa/9/它仍然需要调整,你不能点击链接,但它可以正常工作:)

You can't do this from parent frame. 您不能从父框架执行此操作。 You must add iScroll's script directly to "http://www.css-tricks.com" page. 您必须将iScroll的脚本直接添加到"http://www.css-tricks.com"页面。 If this site doesn't belong to you, you can't do this because executing JavaScript code on pages from different domain is forbidden for security reasons. 如果此站点不属于您,则无法执行此操作,因为出于安全原因,禁止在来自不同域的页面上执行JavaScript代码。

You can set very big height of frame, so scroll bar inside the frame will disappear, only the scroll bar of parent frame will remain. 您可以设置非常大的框架高度,因此框架内的滚动条将消失,仅保留父框架的滚动条。 This scrollbar can be styled with JavaScript because it belongs to your domain. 此滚动条可以使用JavaScript设置样式,因为它属于您的域。 But I think scrolling page with mouse inside frame will not work (you can't receive mouse events from third-party frame). 但我认为使用鼠标内框滚动页面将无效(您无法从第三方框架接收鼠标事件)。 And page height becomes very big (you can't determine the height of frame contents). 并且页面高度变得非常大(您无法确定帧内容的高度)。

Well, you can download entire page contents on server side and display its copy on your site. 那么,您可以在服务器端下载整个页面内容并在您的站点上显示其副本。 In this case JavaScript on this page will work and scrollbar can be styled. 在这种情况下,此页面上的JavaScript将起作用,并且可以设置滚动条的样式。 There are several scripts for doing this. 有几个脚本可以执行此操作。 Trey're called "web proxies". Trey称为“网络代理”。 You can use one of them, for example, PHProxy . 您可以使用其中一个,例如, PHProxy It's complicated to implement this functionality yourself because there are some techinal difficulties (downloading related files, redirecting ajax requests, saving cookies etc). 自己实现这个功能很复杂,因为有一些技术上的困难(下载相关文件,重定向ajax请求,保存cookie等)。

hey ajajy you have to add class also in your file 嘿ajajy你必须在你的文件中添加类

<iframe src="http://www.css-tricks.com" width="360" height="500" id="navbar" class="navbar_relative"></iframe>

and js funcation 和js功能

function magentoScrollMimic(){
 j(document).scroll(function(e){
      if(j(window).scrollTop()>138)
        {
            j('#dynFrame').addClass('navbar_fixed');
            j('#dynFrame').removeClass('navbar_relative');

        }
        else
        {
            j('#dynFrame').removeClass('navbar_fixed');
            j('#dynFrame').addClass('navbar_relative');
        }
   }); 
}

samjyo samjyo

and use directly 并直接使用

<ul id="dynFrame" class="navbar_relative">

i used this and its working 我用它和它的工作

j(document).ready(function(){
    magentoScrollMimic(); }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM