JavaScript瀏覽器選項(xiàng)卡效果
更新時(shí)間:2010年08月25日 21:50:06 作者:
項(xiàng)目需要做了如下的東西,希望能給其他需要的同學(xué)們一點(diǎn)參考。
有圖如下:

代碼如下:
/*
head html : <span></span>
body html : <iframe></iframe>
*/
var Tab = function(id,title,url,isClose){
this.id = id;
this.title = title;
this.url = url;
this.head = jQuery('<span class="tab-head">' + this.title +'</span>');
this.body = jQuery('<iframe name="ifm' + this.id +'" src="' + this.url +'" frameborder=0 class="tab-body"></iframe>').hide();
isClose && (this.close = jQuery('<span class="tab-head-closeBtn">×</span>'),this.closeBtn());
};
Tab.prototype = {
closeBtn : function(){
var self = this;
self.close.bind("mouseover",function(){
jQuery(this).addClass("tab-closeBtn-hover");
});
self.close.bind("mouseout",function(){
jQuery(this).removeClass("tab-closeBtn-hover");
});
self.head.append(self.close);
},
getFocus : function(){
this.head.addClass("tab-head-active");
this.body.show();
},
loseFocus : function(){
this.head.removeClass("tab-head-active");
this.body.hide();
},
destory : function(){
this.head.remove();
this.body.remove();
},
};
/*
head html : <div><span></span><span></span>...</div>
body html : <div><iframe></iframe><iframe></iframe>...</div>
*/
var TabView = function(container){
this.container = container;
this.head = jQuery('<div class="tabView-head"></div>');
this.body = jQuery('<div class="tabView-body"></div>');
this.tabs = [];
this.tabId = 0;
this.focusTab = null;
this.init();
};
TabView.prototype = {
init : function(){
this.container.append(this.head).append(this.body);
},
add : function(title,url,isClose){
var self = this;
var tab = new Tab(self.tabId,title,url,isClose);
self._tabEvents(tab);
(self.tabs.length==0) && (tab.getFocus(),self.focusTab=tab);
self.tabs.push(tab);
self.head.append(tab.head);
self.body.append(tab.body);
self.tabId++;
},
remove_ref : function(tab){
var self = this;
for(var i=0;i<self.tabs.length;i++){
if(tab.id===self.tabs[i].id){
tab.destory();
self.tabs.splice(i,1);
return i;
}
}
return -1;
},
destory : function(){
this.head.remove();
this.body.remove();
},
_tabEvents : function(tab){
var self = this;
tab.head.bind("click",function(){
if(self.focusTab.id != tab.id){
tab.getFocus();
self.focusTab.loseFocus();
self.focusTab = tab;
}
});
tab.close && tab.close.bind("click",function(){
tab.destory();
var i = self.remove_ref(tab);
if(tab.id==self.focusTab.id){//如果關(guān)閉的是當(dāng)前的tab
if(self.tabs.length==0){//如果所有tab都已關(guān)閉
self.destory();
}else{
var nextIndex = self.tabs.length==i ? i-1 : i;
self.focusTab = self.tabs[nextIndex];
self.focusTab.getFocus();
}
}
});
},
};

代碼如下:
復(fù)制代碼 代碼如下:
/*
head html : <span></span>
body html : <iframe></iframe>
*/
var Tab = function(id,title,url,isClose){
this.id = id;
this.title = title;
this.url = url;
this.head = jQuery('<span class="tab-head">' + this.title +'</span>');
this.body = jQuery('<iframe name="ifm' + this.id +'" src="' + this.url +'" frameborder=0 class="tab-body"></iframe>').hide();
isClose && (this.close = jQuery('<span class="tab-head-closeBtn">×</span>'),this.closeBtn());
};
Tab.prototype = {
closeBtn : function(){
var self = this;
self.close.bind("mouseover",function(){
jQuery(this).addClass("tab-closeBtn-hover");
});
self.close.bind("mouseout",function(){
jQuery(this).removeClass("tab-closeBtn-hover");
});
self.head.append(self.close);
},
getFocus : function(){
this.head.addClass("tab-head-active");
this.body.show();
},
loseFocus : function(){
this.head.removeClass("tab-head-active");
this.body.hide();
},
destory : function(){
this.head.remove();
this.body.remove();
},
};
/*
head html : <div><span></span><span></span>...</div>
body html : <div><iframe></iframe><iframe></iframe>...</div>
*/
var TabView = function(container){
this.container = container;
this.head = jQuery('<div class="tabView-head"></div>');
this.body = jQuery('<div class="tabView-body"></div>');
this.tabs = [];
this.tabId = 0;
this.focusTab = null;
this.init();
};
TabView.prototype = {
init : function(){
this.container.append(this.head).append(this.body);
},
add : function(title,url,isClose){
var self = this;
var tab = new Tab(self.tabId,title,url,isClose);
self._tabEvents(tab);
(self.tabs.length==0) && (tab.getFocus(),self.focusTab=tab);
self.tabs.push(tab);
self.head.append(tab.head);
self.body.append(tab.body);
self.tabId++;
},
remove_ref : function(tab){
var self = this;
for(var i=0;i<self.tabs.length;i++){
if(tab.id===self.tabs[i].id){
tab.destory();
self.tabs.splice(i,1);
return i;
}
}
return -1;
},
destory : function(){
this.head.remove();
this.body.remove();
},
_tabEvents : function(tab){
var self = this;
tab.head.bind("click",function(){
if(self.focusTab.id != tab.id){
tab.getFocus();
self.focusTab.loseFocus();
self.focusTab = tab;
}
});
tab.close && tab.close.bind("click",function(){
tab.destory();
var i = self.remove_ref(tab);
if(tab.id==self.focusTab.id){//如果關(guān)閉的是當(dāng)前的tab
if(self.tabs.length==0){//如果所有tab都已關(guān)閉
self.destory();
}else{
var nextIndex = self.tabs.length==i ? i-1 : i;
self.focusTab = self.tabs[nextIndex];
self.focusTab.getFocus();
}
}
});
},
};
您可能感興趣的文章:
- javascript實(shí)現(xiàn)表現(xiàn)、結(jié)構(gòu)、行為分離的選項(xiàng)卡效果!
- javascript漸變顯示的雅虎中國(guó)選項(xiàng)卡效果代碼
- 用javascript實(shí)現(xiàn)的不錯(cuò)的一款網(wǎng)頁(yè)選項(xiàng)卡
- javascript橫排豎排標(biāo)準(zhǔn)選項(xiàng)卡效果代碼
- js實(shí)現(xiàn)tab選項(xiàng)卡函數(shù)代碼
- 純php打造的tab選項(xiàng)卡效果代碼(不用js)
- 跨瀏覽器通用、可重用的選項(xiàng)卡tab切換js代碼
- 利用js實(shí)現(xiàn)選項(xiàng)卡的特別效果的實(shí)例
- javascript實(shí)現(xiàn)tabs選項(xiàng)卡切換效果(自寫原生js)
- jsp js鼠標(biāo)移動(dòng)到指定區(qū)域顯示選項(xiàng)卡離開(kāi)時(shí)隱藏示例
- js/jQuery簡(jiǎn)單實(shí)現(xiàn)選項(xiàng)卡功能
- 基于JavaScript實(shí)現(xiàn)通用tab選項(xiàng)卡(通用性強(qiáng))
相關(guān)文章
JSON中雙引號(hào)的輪回使用過(guò)程中一定要小心
如果JSON對(duì)象中有屬性是包含雙引號(hào)當(dāng)轉(zhuǎn)換成字符串形式,將自動(dòng)加上反斜線,詳細(xì)請(qǐng)祥看本文2014-03-03老生常談jacascript DOM節(jié)點(diǎn)獲取
下面小編就為大家?guī)?lái)一篇老生常談jacascript DOM節(jié)點(diǎn)獲取。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-04-04js阻止移動(dòng)端頁(yè)面滾動(dòng)的兩種方法
本文主要介紹了js阻止移動(dòng)端頁(yè)面滾動(dòng)的兩種方法。具有很好的參考價(jià)值,下面跟著小編一起來(lái)看下吧2017-01-01javascript 禁止復(fù)制網(wǎng)頁(yè)
常見(jiàn)的一些禁止復(fù)制網(wǎng)頁(yè)的代碼,但破解方法也不見(jiàn)容易,這里就不說(shuō)了,可以看本站以前發(fā)布的文章。2009-06-06跨瀏覽器通用、可重用的選項(xiàng)卡tab切換js代碼
今天一同學(xué)對(duì)我說(shuō)“好吧,我準(zhǔn)備去學(xué)習(xí)”。我大驚,這老勾引我打dota的寂寞男竟然也去學(xué)習(xí),于是我好奇他學(xué)什么,他說(shuō)要搞一個(gè)選項(xiàng)卡切換js2011-09-09JavaScript比較當(dāng)前時(shí)間是否在指定時(shí)間段內(nèi)的方法
這篇文章主要介紹了JavaScript比較當(dāng)前時(shí)間是否在指定時(shí)間段內(nèi)的方法,涉及javascript時(shí)間與字符串的轉(zhuǎn)換及比較操作相關(guān)技巧,需要的朋友可以參考下2016-08-08hash特點(diǎn)、hashchange事件介紹及其常見(jiàn)應(yīng)用場(chǎng)景
淺析hash特點(diǎn)、hashchange事件介紹及其常見(jiàn)應(yīng)用場(chǎng)景(不同hash對(duì)應(yīng)不同事件處理、移動(dòng)端大圖展示狀態(tài)后退頁(yè)面問(wèn)題、原生輕應(yīng)用頭部后退問(wèn)題、移動(dòng)端自帶返回按鈕二次確認(rèn)問(wèn)題),hashchange和popstate事件觸發(fā)條件2023-11-11