js 网站顶部通用导航
js代码:
(function (scriptId, styleVersion) {
var hotgameData = {
'title': '热门游戏',
'list': [
{'text': '星座召唤', 'status':'', 'href': 'http://xzzh.xiaoyou-game.com','img': 'http://att1.niucdn.com/woniu.com/2015/0513/df26a116d64062121f3a707c9d63ac44c18b6c7b.jpeg'}
,{'text': '风暴神域', 'status':'', 'href': 'http://fbsy.xiaoyou-game.com/web/list/test.shtml','img': 'http://att1.niucdn.com/woniu.com/2015/0513/afe0639a92437a9e23d81d1aa7a85fa37e2db1bf.jpeg'}
]
};
gameHtml = '<div class="xy-gamehead-hotgame"><div class="xy-gamehead-hotgametitle">'+hotgameData['title']+'</div><div class="xy-gamehead-clearfix">';
for (var i=0; i<hotgameData['list'].length; i++) {
gameHtml += '<a title="'+hotgameData['list'][i]['text']+'" class="xy-gamehead-hotgameli" href="'+hotgameData['list'][i]['href']+'" target="_self"><img alt="'+hotgameData['list'][i]['text']+'" src="'+hotgameData['list'][i]['img']+'">'+hotgameData['list'][i]['text']+'</a>';
}
gameHtml += '</div></div>';
loginHtml = '<li >'+data.value+'<em>|</em></li><li><a class="xy-gamehead-navbtn" href="">注销</a></li>';
var gameheadHtml = [
'<div class="xy-gamehead">',
'<div class="xy-gamehead-contain">',
'<div class="xy-gamehead-nav">',
'<ul>',
loginHtml,
'<div class="xy-gamehead-navlayermask"></div>',
'<li>',
'<a title="逍游天下游戏" class="xy-gamehead-navbtn" href="http://xiaoyou-game.com/" target="_self"><i></i>逍游天下游戏<em></em></a>',
'<div class="xy-gamehead-navlayer xy-gamehead-gamelayer">',
gameHtml,
'</div>',
'<div class="xy-gamehead-navlayermask"></div>',
'</li>',
'<li>',
'<a title="用户中心" class="xy-gamehead-navbtn" href="" target="_self">用户中心</a>',
'<div class="xy-gamehead-navlayermask"></div>',
'</li>',
'</ul>',
'</div>',
'</div>',
'</div>'];
// 插入头部DOM结构
function createHeadFn(){
var pageBody = document.body;
var headObj = document.getElementById('j-xy-gamehead');
if (!headObj) {
headObj = document.createElement("div");
headObj.id = 'j-xy-gamehead';
pageBody.insertBefore(headObj, pageBody.firstChild);
}
headObj.innerHTML = gameheadHtml.join('');
// 二级菜单交互
var navLi = headObj.getElementsByTagName('li');
for (var i=0; i<navLi.length; i++) {
navLi[i].onmouseover = function(){
if (this.className != 'current') {
this.className = 'current';
var layerObj, maskObj;
var navLiDiv = this.getElementsByTagName('div');
var listObjArray = [];
for (var j=0; j<navLiDiv.length; j++) {
var classNames = navLiDiv[j].className.split(' ');
for (var k=0; k<classNames.length; k++) {
if (classNames[k] == 'xy-gamehead-navlayer') {layerObj = navLiDiv[j];}
if (classNames[k] == 'xy-gamehead-navlayermask') {maskObj = navLiDiv[j];}
if (classNames[k] == 'xy-gamehead-navlayer-list') {
listObjArray.push(navLiDiv[j]);
}
}
}
if (layerObj && maskObj && maskObj.offsetWidth == 0) {
var listHeight = 0;
for (var j=0; j<listObjArray.length; j++) {
if (listObjArray[j].clientHeight > listHeight) {listHeight = listObjArray[j].clientHeight;}
}
for (var j=0; j<listObjArray.length; j++) {
listObjArray[j].style.height = (listHeight - 10) + 'px';
}
maskObj.style.width = layerObj.offsetWidth + 'px';
maskObj.style.height = layerObj.offsetHeight + 'px';
}
}
};
if ('onmouseleave' in navLi[i]) {
navLi[i].onmouseleave = function(event){
this.className = '';
};
} else {
navLi[i].onmouseout = function(event){
this.className = '';
};
}
}
}
// 创建引入样式文件
var gameheadCssHref = 'abc.css';
var pageHead = document.getElementsByTagName('head')[0],
gameheadCss = document.createElement('link');
gameheadCss.setAttribute('rel', 'stylesheet');
gameheadCss.setAttribute('type', 'text/css');
gameheadCss.setAttribute('href', gameheadCssHref );
gameheadCss.onload = function(){
createHeadFn();
};
gameheadCss.onerror = function(){
if (window.console) {console.log(gameheadCssHref + '加载失败');}
};
var userAgent = navigator.userAgent.toLowerCase();
if (userAgent.indexOf('windows') > -1 && userAgent.indexOf('chrome') < 0 && userAgent.indexOf('safari') > -1) {
function poll(){
if (gameheadCss['sheet']) {
createHeadFn();
} else {
setTimeout(poll, 1);
}
}
setTimeout(poll, 0);
}
pageHead.appendChild(gameheadCss);
})('xy-gamehead', '3.0.2');
登陆之后显示用户名,未登录显示登录与注册。
$.ajax({
url:'aaa',
async: true,
type:"get",
dataType:'json',
success:function(data,status){
if(data.key == 1){
(function (scriptId, styleVersion) {
var hotgameData = {
'title': '热门游戏',
'list': [
{'text': '星座召唤', 'status':'', 'href': 'http://xzzh.xiaoyou-game.com','img': 'http://att1.niucdn.com/woniu.com/2015/0513/df26a116d64062121f3a707c9d63ac44c18b6c7b.jpeg'}
,{'text': '风暴神域', 'status':'', 'href': 'http://fbsy.xiaoyou-game.com/web/list/test.shtml','img': 'http://att1.niucdn.com/woniu.com/2015/0513/afe0639a92437a9e23d81d1aa7a85fa37e2db1bf.jpeg'}
]
};
gameHtml = '<div class="xy-gamehead-hotgame"><div class="xy-gamehead-hotgametitle">'+hotgameData['title']+'</div><div class="xy-gamehead-clearfix">';
for (var i=0; i<hotgameData['list'].length; i++) {
gameHtml += '<a title="'+hotgameData['list'][i]['text']+'" class="xy-gamehead-hotgameli" href="'+hotgameData['list'][i]['href']+'" target="_self"><img alt="'+hotgameData['list'][i]['text']+'" src="'+hotgameData['list'][i]['img']+'">'+hotgameData['list'][i]['text']+'</a>';
}
gameHtml += '</div></div>';
loginHtml = '<li >'+data.value+'<em>|</em></li><li><a class="xy-gamehead-navbtn" href="">注销</a></li>';
var gameheadHtml = [
'<div class="xy-gamehead">',
'<div class="xy-gamehead-contain">',
'<div class="xy-gamehead-nav">',
'<ul>',
loginHtml,
'<div class="xy-gamehead-navlayermask"></div>',
'<li>',
'<a title="逍游天下游戏" class="xy-gamehead-navbtn" href="http://xiaoyou-game.com/" target="_self"><i></i>逍游天下游戏<em></em></a>',
'<div class="xy-gamehead-navlayer xy-gamehead-gamelayer">',
gameHtml,
'</div>',
'<div class="xy-gamehead-navlayermask"></div>',
'</li>',
'<li>',
'<a title="用户中心" class="xy-gamehead-navbtn" href="" target="_self">用户中心</a>',
'<div class="xy-gamehead-navlayermask"></div>',
'</li>',
'</ul>',
'</div>',
'</div>',
'</div>'];
// 插入头部DOM结构
function createHeadFn(){
var pageBody = document.body;
var headObj = document.getElementById('j-xy-gamehead');
if (!headObj) {
headObj = document.createElement("div");
headObj.id = 'j-xy-gamehead';
pageBody.insertBefore(headObj, pageBody.firstChild);
}
headObj.innerHTML = gameheadHtml.join('');
// 二级菜单交互
var navLi = headObj.getElementsByTagName('li');
for (var i=0; i<navLi.length; i++) {
navLi[i].onmouseover = function(){
if (this.className != 'current') {
this.className = 'current';
var layerObj, maskObj;
var navLiDiv = this.getElementsByTagName('div');
var listObjArray = [];
for (var j=0; j<navLiDiv.length; j++) {
var classNames = navLiDiv[j].className.split(' ');
for (var k=0; k<classNames.length; k++) {
if (classNames[k] == 'xy-gamehead-navlayer') {layerObj = navLiDiv[j];}
if (classNames[k] == 'xy-gamehead-navlayermask') {maskObj = navLiDiv[j];}
if (classNames[k] == 'xy-gamehead-navlayer-list') {
listObjArray.push(navLiDiv[j]);
}
}
}
if (layerObj && maskObj && maskObj.offsetWidth == 0) {
var listHeight = 0;
for (var j=0; j<listObjArray.length; j++) {
if (listObjArray[j].clientHeight > listHeight) {listHeight = listObjArray[j].clientHeight;}
}
for (var j=0; j<listObjArray.length; j++) {
listObjArray[j].style.height = (listHeight - 10) + 'px';
}
maskObj.style.width = layerObj.offsetWidth + 'px';
maskObj.style.height = layerObj.offsetHeight + 'px';
}
}
};
if ('onmouseleave' in navLi[i]) {
navLi[i].onmouseleave = function(event){
this.className = '';
};
} else {
navLi[i].onmouseout = function(event){
this.className = '';
};
}
}
}
// 创建引入样式文件
var gameheadCssHref = 'abc.css';
var pageHead = document.getElementsByTagName('head')[0],
gameheadCss = document.createElement('link');
gameheadCss.setAttribute('rel', 'stylesheet');
gameheadCss.setAttribute('type', 'text/css');
gameheadCss.setAttribute('href', gameheadCssHref );
gameheadCss.onload = function(){
createHeadFn();
};
gameheadCss.onerror = function(){
if (window.console) {console.log(gameheadCssHref + '加载失败');}
};
var userAgent = navigator.userAgent.toLowerCase();
if (userAgent.indexOf('windows') > -1 && userAgent.indexOf('chrome') < 0 && userAgent.indexOf('safari') > -1) {
function poll(){
if (gameheadCss['sheet']) {
createHeadFn();
} else {
setTimeout(poll, 1);
}
}
setTimeout(poll, 0);
}
pageHead.appendChild(gameheadCss);
})('xy-gamehead', '3.0.2');
}else{
(function (scriptId, styleVersion) {
var hotgameData = {
'title': '热门游戏',
'list': [
{'text': '星座召唤', 'status':'', 'href': 'http://xzzh.xiaoyou-game.com','img': 'http://att1.niucdn.com/woniu.com/2015/0513/df26a116d64062121f3a707c9d63ac44c18b6c7b.jpeg'}
,{'text': '风暴神域', 'status':'', 'href': 'http://fbsy.xiaoyou-game.com/web/list/test.shtml','img': 'http://att1.niucdn.com/woniu.com/2015/0513/afe0639a92437a9e23d81d1aa7a85fa37e2db1bf.jpeg'}
]
};
gameHtml = '<div class="xy-gamehead-hotgame"><div class="xy-gamehead-hotgametitle">'+hotgameData['title']+'</div><div class="xy-gamehead-clearfix">';
for (var i=0; i<hotgameData['list'].length; i++) {
gameHtml += '<a title="'+hotgameData['list'][i]['text']+'" class="xy-gamehead-hotgameli" href="'+hotgameData['list'][i]['href']+'" target="_self"><img alt="'+hotgameData['list'][i]['text']+'" src="'+hotgameData['list'][i]['img']+'">'+hotgameData['list'][i]['text']+'</a>';
}
gameHtml += '</div></div>';
loginHtml = '<li ><a class="xy-gamehead-navbtn" href="">登录</a></li><li><a class="xy-gamehead-navbtn" href="">注册</a></li>';
var gameheadHtml = [
'<div class="xy-gamehead">',
'<div class="xy-gamehead-contain">',
'<div class="xy-gamehead-nav">',
'<ul>',
loginHtml,
'<div class="xy-gamehead-navlayermask"></div>',
'</li>',
'<li>',
'<a title="逍游天下游戏" class="xy-gamehead-navbtn" href="" target="_self"><i></i>逍游天下游戏<em></em></a>',
'<div class="xy-gamehead-navlayer xy-gamehead-gamelayer">',
gameHtml,
'</div>',
'<div class="xy-gamehead-navlayermask"></div>',
'</li>',
'<li>',
'<a title="我的账户" class="xy-gamehead-navbtn" href="" target="_self">用户中心</a>',
'<div class="xy-gamehead-navlayermask"></div>',
'</li>',
'</ul>',
'</div>',
'</div>',
'</div>'];
// 插入头部DOM结构
function createHeadFn(){
var pageBody = document.body;
var headObj = document.getElementById('j-xy-gamehead');
if (!headObj) {
headObj = document.createElement("div");
headObj.id = 'j-xy-gamehead';
pageBody.insertBefore(headObj, pageBody.firstChild);
}
headObj.innerHTML = gameheadHtml.join('');
// 二级菜单交互
var navLi = headObj.getElementsByTagName('li');
for (var i=0; i<navLi.length; i++) {
navLi[i].onmouseover = function(){
if (this.className != 'current') {
this.className = 'current';
var layerObj, maskObj;
var navLiDiv = this.getElementsByTagName('div');
var listObjArray = [];
for (var j=0; j<navLiDiv.length; j++) {
var classNames = navLiDiv[j].className.split(' ');
for (var k=0; k<classNames.length; k++) {
if (classNames[k] == 'xy-gamehead-navlayer') {layerObj = navLiDiv[j];}
if (classNames[k] == 'xy-gamehead-navlayermask') {maskObj = navLiDiv[j];}
if (classNames[k] == 'xy-gamehead-navlayer-list') {
listObjArray.push(navLiDiv[j]);
}
}
}
if (layerObj && maskObj && maskObj.offsetWidth == 0) {
var listHeight = 0;
for (var j=0; j<listObjArray.length; j++) {
if (listObjArray[j].clientHeight > listHeight) {listHeight = listObjArray[j].clientHeight;}
}
for (var j=0; j<listObjArray.length; j++) {
listObjArray[j].style.height = (listHeight - 10) + 'px';
}
maskObj.style.width = layerObj.offsetWidth + 'px';
maskObj.style.height = layerObj.offsetHeight + 'px';
}
}
};
if ('onmouseleave' in navLi[i]) {
navLi[i].onmouseleave = function(event){
this.className = '';
};
} else {
navLi[i].onmouseout = function(event){
this.className = '';
};
}
}
}
// 创建引入样式文件
var gameheadCssHref = 'abc.css';
var pageHead = document.getElementsByTagName('head')[0],
gameheadCss = document.createElement('link');
gameheadCss.setAttribute('rel', 'stylesheet');
gameheadCss.setAttribute('type', 'text/css');
gameheadCss.setAttribute('href', gameheadCssHref );
gameheadCss.onload = function(){
createHeadFn();
};
gameheadCss.onerror = function(){
if (window.console) {console.log(gameheadCssHref + '加载失败');}
};
var userAgent = navigator.userAgent.toLowerCase();
if (userAgent.indexOf('windows') > -1 && userAgent.indexOf('chrome') < 0 && userAgent.indexOf('safari') > -1) {
function poll(){
if (gameheadCss['sheet']) {
createHeadFn();
} else {
setTimeout(poll, 1);
}
}
setTimeout(poll, 0);
}
pageHead.appendChild(gameheadCss);
})('xy-gamehead', '3.0.2');
}
},
error:function(){
alert('error');
}
})
js 网站顶部通用导航的更多相关文章
- js 网站顶部导航栏
(function(){ var map = { 'index' : 0, 'gift_code' : 1, 'base_info' : 1, 'band_phone': 1, 'unlink_pho ...
- 为SharePoint网站创建自定义导航菜单
转:http://kaneboy.blog.51cto.com/1308893/397779 相信不少人都希望把SharePoint网站内置的那个顶部导航菜单,换成自己希望的样式.由于SharePoi ...
- jQuery网站顶部定时折叠广告
效果体验:http://hovertree.com/texiao/jquery/4.htm HTML文件代码: <!DOCTYPE html> <html xmlns="h ...
- SharePoint 2010顶部链接导航栏的详细操作
转:http://www.360sps.com/Item/UseTopLink.aspx 在SharePoint 2010环境的页面中,导航链接总体上可以分为两类,一类是显示在左侧的快速启动栏,另一类 ...
- Jq_网站顶部定时折叠广告
<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml"><head><titl ...
- 一款基于jquery固定于顶部的导航
今天给大家分享一款基于jquery固定于顶部的导航,这款导航当浏览器滚动条位于顶部时,导航高度较高,当浏览器滚动向下滚动时,导航高度自动减低,并位于顶部.效果图如下: 在线预览 源码下载 实现的代 ...
- 一款基于jquery滑动后固定于顶部的导航
之前已为大家介绍了好多css3实现的导航菜单.今天分享一款基于jquery滑动后固定于顶部的导航.这款导航的特点是初始位于顶部下面一百个像素,当鼠标滚动时到下方,导航一直处于顶部.效果图如下: 在线预 ...
- swiper 、css3制作移动端网站,折叠导航
swiper .css3制作移动端网站,折叠导航 前几天公司要更新改版移动端的官网,由于网站本身没有多少内容,所以设计师就做成了整屏滑动的样子,起初我并没有看设计稿就一口答应了,拿到手后发现了几个问题 ...
- JS网站图集相册特效
JS网站图集相册特效是一款可以直接使用鼠标进行前后导航,也可以通过缩略图来切换图片. 在线演示本地下载
随机推荐
- 数据库设计 Assignment 02
需求 1.0 请你试分析一下老师(教职工号,老师姓名,年龄),学生(学号,姓名,年龄),课程(课程号,课程名称,开课时间,上课地点)之间的关系, 注:多个老师可以同时教一门课 尝试画出该模型的E-R图 ...
- Android自定义View自定义属性
1.引言 对于自定义属性,大家肯定都不陌生,遵循以下几步,就可以实现: 自定义一个CustomView(extends View )类 编写values/attrs.xml,在其中编写styleabl ...
- Android自定义View (二) 进阶
转载请标明出处:http://blog.csdn.net/lmj623565791/article/details/24300125 继续自定义View之旅,前面已经介绍过一个自定义View的基础的例 ...
- code异常处理
private void copyPrivateRawResuorceToPubliclyAccessibleFile() { InputStream inputStream = null; File ...
- 从零开始学iPhone开发(1)——工具的使用
前提:已经具备了苹果电脑或者iMac,或者安装好了x86苹果而且已经联网. 苹果系统版本要求是:Max OS X Lion,或者 Mountain Lion 我们对iPhone进行使用的工具是XCod ...
- 运用C#生成docx格式的报表
这几天在北京做一个大桥的监测系统的项目,涉及到一个功能,那就是采集数据,处理后,希望能自动生成一个报表,只需要在一个模板的基础上加几个数就可以了,但因为希望生成的是.docx格式的word2007/2 ...
- Redis - 作为 LRU 缓存
一.简介 LRU 实际上是被唯一支持的数据移除方法,同时也是 memcached 默认支持的缓存算法. 二.配置内存大小 在 redis.conf 文件中使用 maxmemory 指令能够配置内存大小 ...
- Excle隐藏及展开列
当excle文档类目比较多的时候我们希望看第一列和某一列的对应关系可以选择隐藏中间列. 选中要隐藏的列,然后右键-->隐藏即可 需要展开的时候,选中:被隐藏列的前一列和后一列,然后当鼠标在列头( ...
- Java Performance - 如何调查解决 CPU 问题
随着硬件的发展,往往服务器会配置足够的 CPUs, Java Server/服务器不太有 CPU 问题:但是偶尔因为 代码海量循环 或者 线程安全性(thread safe), 还是会带来 CPU 问 ...
- JAVA利用JXL导出/生成 EXCEL
/** * 导出导出采暖市场部收入.成本.利润明细表 * @author JIA-G-Y */ public String exporExcel(String str) { String str=Se ...