Как показать стрелку на первой вкладке при загрузке страницы - PullRequest
1 голос
/ 24 декабря 2010

Я использую слегка модифицированную версию слайд-шоу с вкладками jQuery на 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>');

1 Ответ

0 голосов
/ 24 декабря 2010

Добавлена ​​

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

Дом готов

...