【问题标题】:Foundation 6 - Populating img tag data-interchange using JavaScript not showing imagesFoundation 6 - 使用不显示图像的 JavaScript 填充 img 标签数据交换
【发布时间】:2018-06-05 19:06:47
【问题描述】:

我正在尝试修复一些代码,这些代码旨在使用 JavaScript 为滑块中的图像生成数据交换值,但除非我有一个 src 标记,否则我无法让它工作,即使那样,唯一的图像显示的是我在 src 标记中引用的任何内容。

我觉得这应该可以工作,因为它似乎与 Foundation 文档中的数据交换设置相匹配,而且我没有在控制台中看到任何表明存在问题的错误。

代码如下:

         var animallink = $('<a></a>').attr('href', animals[randomkeys[a]].link);
                console.dir(animallistitem);

                $('<img />').attr({
                    'data-interchange': '[' + uploaddirectory + animals[randomkeys[a]].images.med + ', small], [' + uploaddirectory + animals[randomkeys[a]].images.med + ', medium],  [' + uploaddirectory + animals[randomkeys[a]].images.lg + ', large]',
                    'class':'orbit-image',
                    'alt': animals[randomkeys[a]].images.alttext
                }).appendTo(animallink);
                var animalcontainer = $('<div></div>').addClass('related__item-content');

                $('<h2>' + dyktext + '</h2>').appendTo(animalcontainer);
                $('<h3></h3>').addClass('related__name').text(nametext + animals[randomkeys[a]].animal).appendTo(animalcontainer);

                if(animals[randomkeys[a]].location != ""){
                    $('<h3></h3>').addClass('related__location').text(locationtext + animals[randomkeys[a]].location).appendTo(animalcontainer);
                }

                var rndnum = Math.round(Math.random() * (animals[randomkeys[a]].animalfacts.length - 1));

                $('<p></p>').addClass('related__description').html(animals[randomkeys[a]].animalfacts[rndnum].replace('\u0026', '&')).appendTo(animalcontainer);
                $('<div></div>').addClass('related__cta').html(morelinktext + ' <i class="fa fa-arrow-circle-right" aria-hidden="true"></i>').appendTo(animalcontainer);

                animalcontainer.appendTo(animallink);

                animallink.appendTo(animallistitem);

                animallistitem.appendTo(animallist);
            });

            var orbit = new Foundation.Orbit($('.related__animal-facts .orbit'));

【问题讨论】:

    标签: javascript zurb-foundation zurb-foundation-6


    【解决方案1】:

    不确定它是否适用于这种情况,但以前在页面加载后添加交换元素时,必须使用 $(document).foundation() 重新初始化 Foundation。虽然我在当前的文档中找不到它的提及。

    【讨论】:

      猜你喜欢
      • 2021-11-30
      • 2014-09-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多