javascript - 使用 Webkit/jQuery 将外部页面加载到当前页面的最佳方式

标签 javascript jquery css animation webkit

我想在 iPad 网络应用程序(没有像 Sencha 等框架)上使用标准网络技术将完整的 HTML 页面加载到当前页面中

我有一个内容页面和一个文章页面。我想将文章页面(包括此特定页面的 javascript/CSS)加载到新的 div 中并设置动画过渡(滑动),但它似乎不起作用。

使用 jQuery 加载功能,CSS/JS 加载不完美,它只适用于 Chrome(不适用于 iPad)。有更好的方法吗?

CSS:

#content-container {
}

#article-container {
position: absolute;
left: @defaultWidth;

width: 100%;
height: 100%;

background-color: @darkGreyColour;

-webkit-transition: left 1s ease-in; 
}

#content-container.animate {
left: -100%;
}

#article-container.animate {
    left: 0;
}

JS

function animateTransition(event) {
    $('#article-container').load('/ #main', function() {
        console.log("Animating...");
        $('#content-container').addClass('animate');
        $('#article-container').addClass('animate');
    });
}

最佳答案

我建议使用 <iframe>加载完整的 HTML 页面。使用 jQuery 的 .load() 加载完整 html 页面的一部分(例如 $("#myElement").load("/index.html #main") )只会加载文档该部分中的 html,因此它不会加载在文档的其他部分中定义的 js/css文章页面。您可以在 jQuery's .load API Page 的“加载页面片段”部分阅读有关此问题的更多信息.

使用 <iframe> :

<iframe src="theArticle.html">
    <p>Your browser does not support iframes.</p>
</iframe>

使用 jQuery 和 .load() 将文章加载到 <div> :

function animateTransition(event) {
    // load the html contained in the tag with id of #main
    $('#article-container').load('myArticle.html #main', function() {
        // load the css
        $('head').load('myCSS.css', function() {
            // load the js
            $.getScript('myScript.js', function() {
                console.log("Animating...");
                $('#content-container').addClass('animate');
                $('#article-container').addClass('animate');
            });
        });
    });
}

关于javascript - 使用 Webkit/jQuery 将外部页面加载到当前页面的最佳方式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7557386/

相关文章:

javascript - 解析错误 : Line 9: Unexpected identifier in react

javascript - 如果数组循环内的项目不可用,则返回零并按工作日排列项目

javascript - Socket.io HTML - 将独特的内容发送到独特的客户的 HTML 页面

jquery - 响应式网页在移动设备上太小

jquery - 溢出文本应动态调整容器大小

html - Logo 应出现在 strip 上

html - 选中单选按钮时的 CSS 选择器

javascript - 使用 jquery 按类隐藏同一父级中的元素

jquery - 用 CSS 拼贴文字

php - 在 Woocommerce 中使用短代码显示带有动态产品 ID 的自定义按钮