javascript - Foundation 6 - 使用不显示图像的 JavaScript 填充 img 标签数据交换
问题描述
我正在尝试修复一些代码,这些代码旨在使用 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'));
解决方案
不确定它是否适用于这种情况,但过去在页面加载后添加交换元素时,必须使用$(document).foundation()
. 尽管我在当前文档中找不到任何提及。
推荐阅读
- swift - ActionSheet 的工具栏问题
- reactjs - React Big CalendarTimezone 问题:知道如何在 0.10.3 版本中使用此修复 #1046?
- r - 减少 Rmarkdown 中 C3 小部件与周围文本之间的太大差距
- python - Line color as a function of column values in pandas dataframe
- c - 在 C 代码中使用原始二进制指令块
- java - Project Reactor 从同一个 Executor 创建多个调度器
- angular - Angular 如何使用 *ngFor 进行单独的图标更改?
- node.js - 如何解决无法获取/错误 nodejs
- databricks - Databricks 在路径上创建视图分区字段
- python - python函数中的变量问题,未定义