Jquery 加载页面时如何在第一个选项卡上显示箭头
我使用的是在上找到的选项卡式jQuery幻灯片的稍加修改的版本。我基本上是想得到一个带有图像的定位div,以便在页面加载时显示。当前,它仅在显示下一个选项卡时出现 下面是我的js代码Jquery 加载页面时如何在第一个选项卡上显示箭头,jquery,jquery-cycle,Jquery,Jquery Cycle,我使用的是在上找到的选项卡式jQuery幻灯片的稍加修改的版本。我基本上是想得到一个带有图像的定位div,以便在页面加载时显示。当前,它仅在显示下一个选项卡时出现 下面是我的js代码 $mainbanner = { context: false, tabs: false, timeout: 7000, // time before next slide appears (in ms) slideSpeed: 1000, // time it take
$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');
}
}
};
$mainbanner={
上下文:错,
标签:假,
超时:7000,//下一张幻灯片出现之前的时间(毫秒)
slideSpeed:1000,//在每张幻灯片中滑动所需的时间(毫秒)
tabSpeed:300,//单击选项卡时在每张幻灯片中滑动所需的时间(毫秒)
fx:‘scrollLeft’,//要使用的幻灯片效果
init:function(){
//设置上下文以帮助加快选择器/提高性能
this.context=$('#mainbanner');
//将选项卡设置为当前硬编码的导航项目
this.tabs=$('ul.tabbed-nav li',this.context);
//从DOM中删除硬编码的导航项
//因为它们没有连接到jQuery循环
this.tabs.remove();
//准备mainbanner和jQuery循环选项卡
这个。preparemainbanner();
},
preparemainbanner:函数(){
//初始化jquery循环插件-
//有关以下选项集的信息,请转到:
// http://malsup.com/jquery/cycle/options.html
$('div.tabbedcontent>ul',$mainbanner.context)。循环({
外汇:$mainbanner.fx,
超时:$mainbanner.timeout,
速度:$mainbanner.slideSpeed,
FastOneEvent:$mainbanner.tabSpeed,
寻呼机:$('ul.tabbed nav',$mainbanner.context),
pagerAnchorBuilder:$mainbanner.prepareTab,
之前:$mainbanner.activateTab,
是的,
停顿:是的
});
},
准备选项卡:功能(i,幻灯片){
//从硬编码选项卡返回标记,用作jQuery循环选项卡
//(将必要的jQuery循环事件附加到选项卡)
返回$mainbanner.tabs.eq(i);
},
激活选项卡:功能(当前幻灯片,下一幻灯片){
//获取活动选项卡
var activeTab=$('a[href=“#”+nextSlide.id+'”,$mainbanner.context);
//在activeTab上插入.tab箭头
activeTab.parent().append(“”);
//如果有活动选项卡
if(activeTab.length){
//从所有其他选项卡中删除活动样式
$mainbanner.tabs.removeClass('on'/*,'tab-arrow'*/);
//将活动样式添加到活动按钮
activeTab.parent().addClass('on');
}
}
};
这是插入div的代码:
activeTab.parent().append('<div class="tab-arrow"></div>');
activeTab.parent().append(“”);
已添加
$('ul.tabbed-nav li:first').append('<div class="tab-arrow"></div>');
$('ul.tabbed-nav li:first')。追加(“”);
到dom ready@Lorenzo(虽然有3个答案,..36是标签)