如何更改 everythingslider 中的主题标签名称?

发布于 2024-12-27 11:47:18 字数 529 浏览 0 评论 0原文

我正在使用 Anysslider,如果您熟悉它,您可能会知道它具有以下功能:

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();
}

我所做的就是在

元素中添加标题那么,我如何也使用这些标题。重命名主题标签?

I am using anythingslider and if you are familiar with it, you might then know that it has the following function:

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

Which you can use to make it generate unique URLs for each slide as if they were pages. But the downside is that it generates generic names for the hashtag. (e.g.

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

My question is, how can you change the names of those hashtags to custom names for each slide?

Right now I am using the following function to make it display each slide title in the navigation bar:

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

And all I do is that I add the title in a <h6> element. So, how could I use these titles to also rename the hashtags?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

久夏青 2025-01-03 11:47:18

您可以关闭默认哈希并使用 onSlideComplete 回调来更新窗口哈希 (演示;和全屏demo):

*注意: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;
    }

});

这里是 另一个演示,使用面板 ID 而不是 h6 ID。

You can turn off the default hash and use the onSlideComplete callback to update the window hash (demo; and full screen demo):

*note: the h6 also has an id (no spaces allowed) vs the text of the h6 (spaces allowed, and used in the navigation tabs)

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>

Script

$('#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;
    }

});

And here's another demo using the panel ID's instead of the h6 ID's.

雨落星ぅ辰 2025-01-03 11:47:18

我从未使用过任何滑块,但如果您想更改它的主题标签,您可以开始在脚本中查找 window.location.hash 来开始,因为哈希生成部分将从那里开始。

I've never used anythingslider but if you want to change it's hashtags, you could start looking for window.location.hash in the script to begin as the hash generating part would start there.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文