页面加载时如何在第一个选项卡上显示箭头
我正在使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
添加
到dom准备就绪
Added
to the dom ready