1
我在我的項目中使用PagePiling ,特別是添加菜單的選項。動態添加選項到腳本
每則只需添加HTML文檔:
<ul id="myMenu">
<li data-menuanchor="firstPage" class="active"><a href="#firstPage">First section</a></li>
<li data-menuanchor="secondPage"><a href="#secondPage">Second section</a></li>
<li data-menuanchor="thirdPage"><a href="#thirdPage">Third section</a></li>
<li data-menuanchor="fourthPage"><a href="#fourthPage">Fourth section</a></li>
</ul>
和JS內:
$('#pagepiling').pagepiling({
anchors: ['firstPage', 'secondPage', 'thirdPage', 'fourthPage', 'lastPage'],
menu: '#myMenu'
});
不過,我想補充的動態菜單元素,例如:
<ul id="myMenu">
while ($loop->have_posts()) : $loop->the_post(); ?>
<li data-menuanchor="<?php sanitize_title(the_title()); ?>"><a href="#<?php sanitize_title(the_title()); ?>"><?php the_title(); ?></a></li>
<?php endwhile; ?>
</ul>
我如何更新js中的選項?
將你的字符串添加到數組和'implode'它到你的js? – Blake
也許你的問題應該是「如何動態添加部分」? 菜單不是問題...問題是動態地將錨點分配給新節。 – Alvaro