Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/89.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript SimpleMather js天气图标_Javascript_Jquery - Fatal编程技术网

Javascript SimpleMather js天气图标

Javascript SimpleMather js天气图标,javascript,jquery,Javascript,Jquery,我正在尝试使用SimpleMather js制作一个天气应用程序。我已经成功地让应用程序显示我当前位置的天气,但我不知道如何让天气图标显示在温度旁边。任何帮助都将不胜感激。 这是我的密码笔: 以下是我尝试使用的图标: html: } jquery if(导航器中的“地理位置”){ $('.js geolocation').show(); }否则{ $('.js geolocation').hide(); } $('.js geolocation')。在('click',function()上{

我正在尝试使用SimpleMather js制作一个天气应用程序。我已经成功地让应用程序显示我当前位置的天气,但我不知道如何让天气图标显示在温度旁边。任何帮助都将不胜感激。 这是我的密码笔: 以下是我尝试使用的图标:

html:

}

jquery if(导航器中的“地理位置”){ $('.js geolocation').show(); }否则{ $('.js geolocation').hide(); }

$('.js geolocation')。在('click',function()上{
navigator.geolocation.getCurrentPosition(函数(位置){
负荷天气(位置坐标纬度+','+位置坐标经度);
});
});
$(文档).ready(函数(){
loadWeather(‘纽约’,“”);
});
功能loadWeather(位置,woeid){
$.SimpleWither({
地点:地点,,
沃伊德:沃伊德,
单位:f,
成功:功能(天气){
html=''+weather.temp+'°;''+weather.units.temp+'';
html+='
  • '+weather.city+,'+weather.region+'
  • '; html+='
  • '+天气。current+'
  • '; html+='
  • '+weather.alt.temp+'°;C
'; $(“#天气”).html(html); }, 错误:函数(错误){ $(“#天气”).html(“”+错误+”

”); } }); }
您的代码似乎工作正常。
确保按以下顺序插入库

  • JQuery
  • 简单天气
  • 别忘了包括天气图标CSS和引导CSS文件

    $(文档).ready(函数(){
    if(导航器中的“地理位置”){
    $('.js geolocation').show();
    }否则{
    $('.js geolocation').hide();
    }
    //按钮处理器
    $('.js geolocation')。在('click',function()上{
    navigator.geolocation.getCurrentPosition(函数(位置){
    loadWeather(position.coords.latitude+','+position.coords.longitude);
    });
    });
    //装载天气
    功能loadWeather(位置,woeid){
    $.SimpleWither({
    地点:地点,,
    沃伊德:沃伊德,
    单位:f,
    成功:功能(天气){
    html=''+weather.temp+'°;''+weather.units.temp+'';
    html+='
    • '+weather.city+'、'+weather.region+'
    • '; html+='
    • '+weather.current+'
    • '; html+='
    • '+weather.alt.temp+'°;C
    '; $(“#天气”).html(html); }, 错误:函数(错误){ $(“#天气”).html(“”+错误+”

    ”); } }); } //初始化 loadWeather(‘迈阿密’,“”); });
    
    使用位置
    
    您的代码似乎工作正常。
    确保按以下顺序插入库

  • JQuery
  • 简单天气
  • 别忘了包括天气图标CSS和引导CSS文件

    $(文档).ready(函数(){
    if(导航器中的“地理位置”){
    $('.js geolocation').show();
    }否则{
    $('.js geolocation').hide();
    }
    //按钮处理器
    $('.js geolocation')。在('click',function()上{
    navigator.geolocation.getCurrentPosition(函数(位置){
    loadWeather(position.coords.latitude+','+position.coords.longitude);
    });
    });
    //装载天气
    功能loadWeather(位置,woeid){
    $.SimpleWither({
    地点:地点,,
    沃伊德:沃伊德,
    单位:f,
    成功:功能(天气){
    html=''+weather.temp+'°;''+weather.units.temp+'';
    html+='
    • '+weather.city+'、'+weather.region+'
    • '; html+='
    • '+weather.current+'
    • '; html+='
    • '+weather.alt.temp+'°;C
    '; $(“#天气”).html(html); }, 错误:函数(错误){ $(“#天气”).html(“”+错误+”

    ”); } }); } //初始化 loadWeather(‘迈阿密’,“”); });
    
    使用位置
    
    根据图标的兼容性页面(),
    wi-yahoo-31
    的等价物是
    night clear
    ,因此您将使用
    ,而不是使用
    ——因此,您需要有一个查找表(将yahoo的图标与天气图标映射)并且每次都使用替换品。这有道理吗?我想有道理。但就代码而言,我现在只得到CSS中的字母占位符。我如何解决这个问题,在将雅虎图标映射到新图标之前,首先让它出现?我以前在html中做过,但没有成功。有什么我遗漏的吗?在代码笔中,你是否包含了天气图标的css?(当我修改您的画笔时,我可以看到夜间清除图标(左下,不居中)更不用说创建您自己的映射了,库已经为您映射了它们。请参见Answer中的运行示例根据图标的兼容性页面(),wi-yahoo-31的等价物是夜晴,因此您将使用
    ,而不是
    ——因此,您需要有一个查找表(将yahoo的图标与天气图标映射),而不是将
    添加到图标中并且每次都使用替换。这有意义吗?我想是的。但就代码而言,我现在只得到CSS中的字母占位符。我如何解决这个问题,首先让yahoo图标出现,然后再将其映射到新图标?我以前在html中做过,但没有成功。我缺少什么吗?在代码笔中,是吗u包括天气图标的css?(当我修改你的画笔时,我可以看到夜空图标(左下,不居中)更不用说创建你自己的映射,库已经为你映射了它们。请参阅答案中的运行示例
    
        <div id="the_weather"></div>
        <button class="js-geolocation"> Use Location</button>
        <i class="wi wi-yahoo-31"></i>
    
    body {
    background-image: url("http://www.psdgraphics.com/file/blue-sky.jpg");
    background-size: cover;
    height: 100%;
    width: 100%;
    }
    
    #the_weather {
    width: 500px;
    text-align: center;
    margin: 0px auto;
    text-transform: uppercase;
    }
    
    @font-face {
    src: url('weathericons-regular-webfont.eot') format ('embedded-opentype');
    src: url('weathericons-regular-webfont.svg') format ('svg');
    src: url('weathericons-regular-webfont.ttf') format('truetype');
    src: url('weathericons-regular-webfont.woff') format('woff');
    src: url('weathericons-regular-webfont.woff2') format('woff2');
    }
    
    i {
    color: #ffffff;
    font-size: 160px;
    font-weight: normal;
    font-style: normal;
    }
    
    #the_weather li {
    display: block;
    font-weight: bold;
    padding: 5px;
    }
    
    .icon-0:before { content: ":"; }
    .icon-1:before { content: "p"; }
    .icon-2:before { content: "S"; }
    .icon-3:before { content: "Q"; }
    .icon-4:before { content: "S"; }
    .icon-5:before { content: "W"; }
    .icon-6:before { content: "W"; }
    .icon-7:before { content: "W"; }
    .icon-8:before { content: "W"; }
    .icon-9:before { content: "I"; }
    .icon-10:before { content: "W"; }
    .icon-11:before { content: "I"; }
    .icon-12:before { content: "I"; }
    .icon-13:before { content: "I"; }
    .icon-14:before { content: "I"; }
    .icon-15:before { content: "W"; }
    .icon-16:before { content: "I"; }
    .icon-17:before { content: "W"; }
    .icon-18:before { content: "U"; }
    .icon-19:before { content: "Z"; }
    .icon-20:before { content: "Z"; }
    .icon-21:before { content: "Z"; }
    .icon-22:before { content: "Z"; }
    .icon-23:before { content: "Z"; }
    .icon-24:before { content: "E"; }
    .icon-25:before { content: "E"; }
    .icon-26:before { content: "3"; }
    .icon-27:before { content: "a"; }
    .icon-28:before { content: "A"; }
    .icon-29:before { content: "a"; }
    .icon-30:before { content: "A"; }
    .icon-31:before { content: "6"; }
    .icon-32:before { content: "1"; }
    .icon-33:before { content: "6"; }
    .icon-34:before { content: "1"; }
    .icon-35:before { content: "W"; }
    .icon-36:before { content: "1"; }
    .icon-37:before { content: "S"; }
    .icon-38:before { content: "S"; }
    .icon-39:before { content: "S"; }
    .icon-40:before { content: "M"; }
    .icon-41:before { content: "W"; }
    .icon-42:before { content: "I"; }
    .icon-43:before { content: "W"; }
    .icon-44:before { content: "a"; }
    .icon-45:before { content: "S"; }
    .icon-46:before { content: "U"; }
    .icon-47:before { content: "S"; }
    
    #weather h2 {
    margin: 0 0 8px;
    color: #fff;
    font-size: 100px;
    font-weight: 300;
    text-align: center;
    text-shadow: 0px 1px 3px rgba(0, 0, 0, 0.15);
    }
    
    #weather ul {
    margin: 0;
    padding: 0;
    }
    
    #weather li {
    background: #fff;
    background: rgba(255,255,255,0.90);
    padding: 20px;
    display: inline-block;
    border-radius: 5px;
    
    #weather .currently {
    margin: 0 20px;
    }
    
    button {
    display: block;
    margin: 15px auto;
    width: 140px;
    padding: 5px;
    background:#efcc3a;
    color: #0;
    font-weight: bold;
    border: 0;
    border-radius: 5px;
    }
    
    $('.js-geolocation').on('click', function() {
    navigator.geolocation.getCurrentPosition(function(position) {
    loadWeather(position.coords.latitude+','+position.coords.longitude);
    });
    });
    
    
    $(document).ready(function() {
    loadWeather('New York','');
    });
    
    function loadWeather(location, woeid) {
    $.simpleWeather({
    location: location,
    woeid: woeid,
    unit: 'f',
    success: function(weather) {
    html = '<h2><i class="icon-'+weather.code+'"></i>          '+weather.temp+'&deg;'+weather.units.temp+'</h2>';
    html += '<ul><li>'+weather.city+', '+weather.region+'</li>';
    html += '<li class="currently">'+weather.currently+'</li>';
    html += '<li>'+weather.alt.temp+'&deg;C</li></ul>';  
    
    $("#the_weather").html(html);
    },
    error: function(error) {
    $("#the_weather").html('<p>'+error+'</p>');
    }
    });
    }