デフォルトのハッシュをオフにし、onSlideComplete
コールバックを使用してウィンドウハッシュを更新できます(デモ;およびフルスクリーンデモ):
*注:h6にはID(スペースは許可されていません)とh6のテキスト(スペースは許可されており、ナビゲーションタブで使用されます)もあります
HTML
<ul id="slider">
<li>
<img src="http://placekitten.com/320/200" alt="" />
<h6 id="meow">Meow</h6>
</li>
<li>
<img src="http://placehold.it/320x200" alt="" />
<h6 id="grey">Grey</h6>
</li>
<li>
<img src="http://placebear.com/320/200" alt="" />
<h6 id="rawr">Rawr</h6>
</li>
<li>
<img src="http://dummyimage.com/320x200/000/fff.jpg" alt="" />
<h6 id="bnw">Black & White</h6>
</li>
<li>
<img src="http://placedog.com/320/200" alt="" />
<h6 id="woof">Woof</h6>
</li>
</ul>
脚本
$('#slider').anythingSlider({
// Should links change the hashtag in the URL?
hashTags: false,
// Details at the top of the file on this use (advanced use)
navigationFormatter: function(index, panel) {
return panel.find('h6').text();
},
// Callback when the plugin finished initializing
onInitialized: function(e, slider) {
slider.$items.find('h6').each(function(){
// add some prefix to the id so setting the hash doesn't
// make the page jump
this.id = "tmp_" + this.id;
});
},
// Callback when slide completes - no event variable!
onSlideComplete: function(slider) {
var hash = '#' + slider.$currentPage.find('h6')[0].id.replace(/tmp_/,'');
// remove prefix so hash works on page load
window.location.hash = hash;
}
});
そして、h6IDの代わりにパネルIDを使用した別のデモがあります。