javascript - 将 URL 加载到 CSS 动画滑动 iframe

标签 javascript jquery css iframe css-animations

我想在 CSS 动画扩展 iframe 中打开一个链接。

我的问题:当我点击链接时,href/url 没有加载。我可以触发 iframe 的 css 动画。 (也许 js 覆盖了 href?)

在某些时候,我将请求分成两个链接进行测试:一个加载扩展的 iframe,另一个用于将页面加载到现在可见的 iframe 中,这很有效。但是一旦我将两个链接放在一起,url 就不会加载。

我尝试了很多其他的东西并搜索了很多 jQuery 插件,但还没有找到合适的解决方案。 在此先感谢您的帮助!

这是现场演示的 fiddle : https://jsfiddle.net/10jew169/2/

这是滑动 iframe 的 css:

 /*iframe styling*/
    #slideiniframe {
        height: 100%;
        position: fixed;
        border: none;
        margin: 0;
        top: 0;
        right: 0;
        background: url(img/preloader.gif) #d8d8d8 center no-repeat;
        max-width: 800px;
    }
    /*iframe animation*/
    .hide {
        overflow: hidden;
        width: 0%;
        padding-top: 0;
        padding-bottom: 0;
        margin-top: 0;
        margin-bottom: 0;
        -moz-transition-duration: 0.3s;
        -webkit-transition-duration: 0.3s;
        -o-transition-duration: 0.3s;
        transition-duration: 0.3s;
        -moz-transition-timing-function: cubic-bezier(0, 1, 0.5, 1);
        -webkit-transition-timing-function: cubic-bezier(0, 1, 0.5, 1);
        -o-transition-timing-function: cubic-bezier(0, 1, 0.5, 1);
        transition-timing-function: cubic-bezier(0, 1, 0.5, 1);
    }
    .show {
        transition-duration: 0.3s;
        -moz-transition-duration: 0.3s;
        -webkit-transition-duration: 0.3s;
        -o-transition-duration: 0.3s;
        transition-timing-function: ease-in;
        -moz-transition-timing-function: ease-in;
        -webkit-transition-timing-function: ease-in;
        -o-transition-timing-function: ease-in;
        width: 50%;
        overflow: hidden;
    }

以及主体的 html 和用于激活 css 动画的 js/jquery:

<!--article preview with two links to the iframe-->
<div class="post-content">
  <h2>The World's Coolest Passport Stamps</h2>
  <div class="body-text">
    <p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit.</p>
    <p><a class="read_more" href="http://travel-and-leisure-yahoopartner.tumblr.com/post/142022520144/the-worlds-coolest-passport-stamps" target="articleiframe">Keep reading</a></p>


<!--full article in iframe-->
<iframe id="slideiniframe" class="hide" name="articleiframe">
<p>Your browser does not support iframes.</p>
</iframe>

<!--slide in animated when clicked on link and hide when clicked elsewhere--> 
<script>
$('.read_more').click(function(){
    $('#slideiniframe').toggleClass('show').toggleClass('hide');
    return false;
});

$(window).ready(function(){
    $('html').click(function(){
    $('#slideiniframe').addClass('hide').removeClass('show');
     });
});
</script>

最佳答案

您需要将 href 值传递给 iFrame 的 src 属性。

$('.read_more').click(function() {
    $('#slideiniframe').prop('src', $(this).prop('href'))
    $('#slideiniframe').toggleClass('show').toggleClass('hide');
    return false;
});

关于javascript - 将 URL 加载到 CSS 动画滑动 iframe,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36412825/

相关文章:

javascript - 使用 setTimeout 在自身内部调用函数

css - 如何将静态和流体布局与 Twitter Bootstrap 相结合?

html - 7个div,如何让他们停留在图片说的地方?

javascript - 具有相同类的多个元素 - 仅在最后一个元素之后插入

jquery - 悬停时缩放图像,没有隐藏文本

javascript - 使用绝对定位的内部 Div 生成相对定位的 Div

javascript - EventPluginUtils.getLowestCommonAncestor(responderInst, targetInst) 错误 native react

javascript - 为对话框获取值

javascript - 在 JS 中查找对象特定值的键

javascript - PHP mysqli执行不返回值