experience

经验

zw-1988.com

home > 经验 > 地图延迟加载

2017.9.28 地图延迟加载

2种方法

1通常用在正常的html页面内

<div class="map"></div>
function loadgooglemap() {
	setTimeout(function () {
		$(".map").load('assets/gm.html');
	}, 500);
}
    
    
    
$(window).on("load", function () {
	loadgooglemap();
});

2通常用在wordpress内写在function.php内

function homeScript(){
    ?>
    <script>
        <?php wp_reset_query(); if ( !is_paged() && ( is_home() || is_front_page() ) ) { ?>

        jQuery(window).on('load', function() {
            setTimeout(function() {
                jQuery("#facebook").load('<?php bloginfo('url');?>/mp/facebook.html');
            }, 500);
        });

        <?php } ?>

    </script>
    <?php }
add_action( 'wp_footer', 'homeScript', 100, 1 );

 

function embedGoogleMap() {
    if ($(".footer-map").find("iframe").length) {
        var map = $(".footer-map").html();
        $(".footer-map").find("iframe").remove();
        $(window).on("load", function () {
            setTimeout(function () {
                $(".footer-map").html(map);
            }, 500);
        });
    }
}
// 在ready事件中执行函数
$(function () {
embedGoogleMap();
});
«
相关文章
wordpress (25)java script (9)tool (8)css (2)攻略 (1)第一次人体 (1)插件 (1)ECharts (1)food (1)雪糕 (1)动画 (1)book (1)标签云 (1)生活 (1)一言难尽的画稿 (1)
辽ICP备16002031号

Copyright © 2016 - 2020 1988-zw.com