页面加载时如何在第一个选项卡上显示箭头

发布于 2024-10-09 01:40:06 字数 2774 浏览 0 评论 0原文

我正在使用 nettuts.com。我基本上试图获取一个定位的 div,并在页面加载时显示图像。目前它仅在显示下一个选项卡时出现。

我的js代码如下

$mainbanner = {
    context: false,
    tabs: false,
    timeout: 7000,      // time before next slide appears (in ms)
    slideSpeed: 1000,   // time it takes to slide in each slide (in ms)
    tabSpeed: 300,      // time it takes to slide in each slide (in ms) when clicking through tabs
    fx: 'scrollLeft',   // the slide effect to use

    init: function() {
        // set the context to help speed up selectors/improve performance
        this.context = $('#mainbanner');

        // set tabs to current hard coded navigation items
        this.tabs = $('ul.tabbed-nav li', this.context);

        // remove hard coded navigation items from DOM 
        // because they aren't hooked up to jQuery cycle
        this.tabs.remove();

        // prepare mainbanner and jQuery cycle tabs
        this.preparemainbanner();


    },

    preparemainbanner: function() {
        // initialise the jquery cycle plugin -
        // for information on the options set below go to: 
        // http://malsup.com/jquery/cycle/options.html
        $('div.tabbedcontent > ul', $mainbanner.context).cycle({
            fx: $mainbanner.fx,
            timeout: $mainbanner.timeout,
            speed: $mainbanner.slideSpeed,
            fastOnEvent: $mainbanner.tabSpeed,
            pager: $('ul.tabbed-nav', $mainbanner.context),
            pagerAnchorBuilder: $mainbanner.prepareTabs,
            before: $mainbanner.activateTab,
            pauseOnPagerHover: true,
            pause: true
        });            
    },

    prepareTabs: function(i, slide) {
        // return markup from hardcoded tabs for use as jQuery cycle tabs
        // (attaches necessary jQuery cycle events to tabs)
        return $mainbanner.tabs.eq(i);
    },

    activateTab: function(currentSlide, nextSlide) {
        // get the active tab
        var activeTab = $('a[href="#' + nextSlide.id + '"]', $mainbanner.context);

    // inserts .tab-arrow on activeTab
    activeTab.parent().append('<div class="tab-arrow"></div>');

        // if there is an active tab
        if(activeTab.length) {
            // remove active styling from all other tabs

            $mainbanner.tabs.removeClass('on'/*,'tab-arrow'*/);


            // add active styling to active button
            activeTab.parent().addClass('on');

        }            
    }            
};

这是插入div的代码:

activeTab.parent().append('<div class="tab-arrow"></div>');

I'm using a slightly modified version of Tabbed jQuery slideshow found on nettuts.com. I'm basically trying to get a positioned div with an image to show up when the page loads. Currently it only appearing when the next tab is shown.

My js code is below

$mainbanner = {
    context: false,
    tabs: false,
    timeout: 7000,      // time before next slide appears (in ms)
    slideSpeed: 1000,   // time it takes to slide in each slide (in ms)
    tabSpeed: 300,      // time it takes to slide in each slide (in ms) when clicking through tabs
    fx: 'scrollLeft',   // the slide effect to use

    init: function() {
        // set the context to help speed up selectors/improve performance
        this.context = $('#mainbanner');

        // set tabs to current hard coded navigation items
        this.tabs = $('ul.tabbed-nav li', this.context);

        // remove hard coded navigation items from DOM 
        // because they aren't hooked up to jQuery cycle
        this.tabs.remove();

        // prepare mainbanner and jQuery cycle tabs
        this.preparemainbanner();


    },

    preparemainbanner: function() {
        // initialise the jquery cycle plugin -
        // for information on the options set below go to: 
        // http://malsup.com/jquery/cycle/options.html
        $('div.tabbedcontent > ul', $mainbanner.context).cycle({
            fx: $mainbanner.fx,
            timeout: $mainbanner.timeout,
            speed: $mainbanner.slideSpeed,
            fastOnEvent: $mainbanner.tabSpeed,
            pager: $('ul.tabbed-nav', $mainbanner.context),
            pagerAnchorBuilder: $mainbanner.prepareTabs,
            before: $mainbanner.activateTab,
            pauseOnPagerHover: true,
            pause: true
        });            
    },

    prepareTabs: function(i, slide) {
        // return markup from hardcoded tabs for use as jQuery cycle tabs
        // (attaches necessary jQuery cycle events to tabs)
        return $mainbanner.tabs.eq(i);
    },

    activateTab: function(currentSlide, nextSlide) {
        // get the active tab
        var activeTab = $('a[href="#' + nextSlide.id + '"]', $mainbanner.context);

    // inserts .tab-arrow on activeTab
    activeTab.parent().append('<div class="tab-arrow"></div>');

        // if there is an active tab
        if(activeTab.length) {
            // remove active styling from all other tabs

            $mainbanner.tabs.removeClass('on'/*,'tab-arrow'*/);


            // add active styling to active button
            activeTab.parent().addClass('on');

        }            
    }            
};

This is the code that inserts the div :

activeTab.parent().append('<div class="tab-arrow"></div>');

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

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

发布评论

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

评论(1

烟燃烟灭 2024-10-16 01:40:06

添加

$('ul.tabbed-nav li:first').append('<div class="tab-arrow"></div>');

到dom准备就绪

Added

$('ul.tabbed-nav li:first').append('<div class="tab-arrow"></div>');

to the dom ready

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