1

私はanythingsliderを使用していますが、これに精通している場合は、次の機能があることをご存知かもしれません。

hashTags : true,      // Should links change the hashtag in the URL?

これを使用して、スライドごとにページであるかのように一意のURLを生成できます。ただし、欠点は、ハッシュタグの総称名が生成されることです。(例えば

http://www.mysite.com/#&panel1-2

私の質問は、これらのハッシュタグの名前を各スライドのカスタム名に変更するにはどうすればよいですか?

現在、次の関数を使用して、ナビゲーションバーに各スライドタイトルを表示しています。

navigationFormatter : function(i, panel){
    return panel.find('h6').text();
}

そして、私がすることは、<h6>要素にタイトルを追加することだけです。では、これらのタイトルを使用してハッシュタグの名前も変更するにはどうすればよいでしょうか。

4

2 に答える 2

2

デフォルトのハッシュをオフにし、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を使用した別のデモがあります。

于 2012-01-17T03:33:24.937 に答える
0

私はanythingsliderを使用したことがありませんが、ハッシュタグを変更したい場合はwindow.location.hash、ハッシュ生成部分がそこから始まるので、スクリプトで開始することを探し始めることができます。

于 2012-01-17T01:44:09.050 に答える