Iframe嵌入天气预报

实现效果

接入天气预报数据

实现方式对比

1、中国气象局气象网络中心目前提供3天天气预报数据,个人申请许可约一周
接口地址:http://smart.weather.com.cn/wzfw/smart/weatherapi.shtml

2、云聚提供较为友好的商业服务,目前来看性价比较高
接口地址:http://www.36wu.com/Service/Details/1?cid=3

3、新浪提供iframe嵌入定制天气模块,当前天天气预报
接口地址:http://weather.news.sina.com.cn/chajian/

4、天气网提供iframe嵌入定制天气,未来五天天气预报
接口地址:http://www.tianqi.com/plugin/

代码示例

Weather.htm

<html lang="zh-CN">
<head>
    <title>Weather from i.tianqi.com</title>
</head>
<body>
    <!--
            参数py:城市全拼,切换城市自行修改,如页面无法显示请直接访问src中地址,查看能否正常显示
     -->
    <iframe name="weather_inc" src="http://i.tianqi.com/index.php?c=code&id=57&py=nanjing"
        style="border: solid 1px #7ec8ea" width="650" height="600" frameborder="0" marginwidth="0"
        marginheight="0" scrolling="no"></iframe>
    <script type="text/javascript">
        var scrollY = 0;
        var maxY = 650; //卷动画面最大高度
        var direction = 0
        function scrollWindow() {
            if (direction == 0) {
                window.scrollBy(0, +1);
                if (scrollY > maxY) {
                    direction = 1;
                }
                else
                    scrollY = scrollY + 2; //每次卷动的单位
            }
            else
            {
                window.scrollTo(0, 0);
                direction = 0;
                scrollY = 0;
            }
        }

        function initialize() {
            timer = setInterval("scrollWindow()", 180); //速度
        }

        initialize();
        document.body.onmouseover = function () { clearInterval(timer); }
        document.body.onmouseout = function () { initialize(); }
    </script>
</body>
</html>

控制显示范围Index.htm

<html lang="zh-CN">
<head>
    <title>Index</title>
</head>
<body>
    <iframe src="Weather.htm" style="border: solid 1px #7ec8ea" width="453" height="247"
        frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe>
</body>
</html>
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • 1. 国家气象局 实时接口:实时天气1:http://www.weather.com.cn/data/sk/101...
    DROP_DATABASE阅读 165,351评论 13 75
  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 177,085评论 25 709
  • 最近在写博客主题的时候发现一个很严重的问题,由于css的命名并不是很规范,导致自己在后期修改的时候很是头疼,有些样...
    枫s的思念阅读 11,187评论 0 8
  • 无声的语言 写在脸上 刻在眉宇间 如果你只匆匆的浏览 你就无法读懂 那深刻的蕴含
    柏莲华阅读 1,751评论 0 2
  • ――西西 小径延展着 尽管只是一棵棵的野草 我也可以肆意繁茂 成一片花的海洋 或者卑微的我, 没有美人的垂怜 当风...
    花语清溪阅读 3,318评论 8 6

友情链接更多精彩内容