重庆分公司,新征程启航

为企业提供网站建设、域名注册、服务器等服务

javascript导航栏,javascript导航栏制作

如何用JavaScript 实现 iOSwebView里面Html界面导航栏置顶效果

//记录导航条原来在页面上的位置

创新互联建站服务项目包括西乡塘网站建设、西乡塘网站制作、西乡塘网页制作以及西乡塘网络营销策划等。多年来,我们专注于互联网行业,利用自身积累的技术优势、行业经验、深度合作伙伴关系等,向广大中小型企业、政府机构等提供互联网行业的解决方案,西乡塘网站推广取得了明显的社会效益与经济效益。目前,我们服务的客户以成都为中心已经辐射到西乡塘省份的部分城市,未来相信会继续扩大服务区域并继续获得客户的支持与信任!

var naviga_offsetTop = 0;

var naviga_offsetLeft = 0;

//IE7不识别getElementsByClassName,为了兼容自定义一个

function my_getElementsByClassName(class_name) {

var el = [];

//获取所有元素

_el = document.getElementsByTagName('*');

//通过className刷选

for (var i=0; i_el.length; i++ ) {

if (_el[i].className == class_name ) {

el[el.length] = _el[i];

}

}

return el;

}

//导航条,悬停在顶部

function naviga_stay_top(){

var a_navigation_bar = [];

if(document.getElementsByClassName){//Chrome, FF

a_navigation_bar = document.getElementsByClassName("navigation");

} else {//IE

a_navigation_bar = my_getElementsByClassName("navigation");

}

var scrollTop = document.body.scrollTop || document.documentElement.scrollTop;

document.title = scrollTop;

//如果向下滚动的距离大于原来导航栏离顶部的距离

//直接将导航栏固定到可视区顶部

if( scrollTop naviga_offsetTop ){

a_navigation_bar[0].style.top = 0 + "px";

} else {

//如果向下滚动的距离小原来导航栏离顶部的距离,则重新计算导航栏的位置

a_navigation_bar[0].style.top = (naviga_offsetTop - scrollTop) + "px";

}

}

//给导航条上四个tab,加上点击事件。

window.onload=function(){

var a_tabs = [];

if( document.getElementsByClassName ){//Chrome, FF

a_tabs = document.getElementsByClassName("tab");

}else{ //IE

a_tabs = my_getElementsByClassName("tab");

}

var a_contents = [];

if( document.getElementsByClassName ){//Chrome, FF

a_contents = document.getElementsByClassName("content");

}else{//IE

a_contents = my_getElementsByClassName("content");

}

//获取offsetLeft,即导航栏离左边框的距离

var a_main_div = [];

if( document.getElementsByClassName ){//Chrome, FF

a_main_div = document.getElementsByClassName("main");

}else{ //IE

a_main_div = my_getElementsByClassName("main");

}

naviga_offsetLeft = a_main_div[0].offsetLeft;

a_tabs[0].onclick=function(){

window.scrollTo(0, a_contents[2].offsetTop);

}

a_tabs[1].onclick=function(){

window.scrollTo(0, a_contents[3].offsetTop);

}

a_tabs[2].onclick=function(){

window.scrollTo(0, a_contents[4].offsetTop);

}

a_tabs[3].onclick=function(){

window.scrollTo(0, a_contents[5].offsetTop);

}

//获取页面上,导航条到顶部的位置

var a_navigation_bar = [];

if(document.getElementsByClassName){//Chrome, FF

a_navigation_bar = document.getElementsByClassName("navigation");

} else {//IE

a_navigation_bar = my_getElementsByClassName("navigation");

}

//获取offsetTop

naviga_offsetTop = a_navigation_bar[0].offsetTop;

a_navigation_bar[0].style.left = naviga_offsetLeft + "px";

//给滚动条以及鼠标加上滚动事件

if( window.attachEvent) //IE

{

window.attachEvent("onmousewheel", naviga_stay_top);

window.attachEvent("onscroll", naviga_stay_top);

document.attachEvent("onmousewheel", naviga_stay_top);

document.attachEvent("onscroll", naviga_stay_top);

} else {//Chrome ,FF

window.addEventListener("mousewheel", naviga_stay_top,false);

window.addEventListener("scroll", naviga_stay_top,false);

document.addEventListener("mousewheel", naviga_stay_top,false);

document.addEventListener("scroll", naviga_stay_top,false);

}

}

导航栏的javascript代码(点击导航栏上链接时。背景图片改成相应的图片,并且刷新也不会变

用Cookies可以实现,这个不太好表达,就是把初始值保存在Cookie中,在根据用户的操作回写Cookie,读取Cookie的参数就可以了,刷新也没关系

纯js怎样实现网站导航栏的切换?

html

head

meta http-equiv="Content-Type" content="text/html; charset=gb2312"

title多选项切换导航菜单/title

/head

style type="text/css"

#dNavBar{

background-color:#ffffff;

}

#dNavBar li{

list-style-type:none;

float:left;

width:84px;

height:28px;

line-height:28px;

font-size:12px;

color:#FFFFFF;

border:1px solid #ffffff;

background:#86C2FF;

text-align:center;

display:block;

cursor:pointer;

}

#subMenu{

background:#99cc66;

width:500px;

border-left:1px solid #ffffff;

border-right:1px solid #ffffff;

height:29px;

line-height:29px;

color:#FFFFFF;

font-size:12px;

padding-left:10px;

}

body {

margin: 0px;

}

a:link,a:visited {

color: #FFFFFF;

text-decoration: none;

}

a:hover{

color: #FFFFFF;

text-decoration: none;

}

/style

script language="javascript"

function ShowMenu()

{

var barCTT=document.getElementByIdx_x("dNavBar")

var liArr=barCTT.getElementsByTagName_r("li")

var links=new Array()

links[0]="a href='#'当前位置:首页"

links[1]="a href='#'项目一/a | a href='#'项目二/a | a href='#'项目三/a | a href='#'项目四/a"

links[2]="a href='#'项目一/a | a href='#'项目二/a | a href='#'项目三/a"

links[3]="a href='#'项目一/a | a href='#'项目二/a | a href='#'项目三/a | a href='#'项目四/a | a href='#'项目五/a"

links[4]="a href='#'项目一/a | a href='#'项目二/a"

links[5]="a href='#'项目一/a | a href='#'项目二/a | a href='#'项目三/a"

links[6]="a href='#'项目一/a | a href='#'项目二/a"

links[7]="a href='#'项目一/a | a href='#'项目二/a"

links[8]="a href='#'项目一/a | a href='#'项目二/a"

links[9]="a href='#'项目一/a | a href='#'项目二/a"

links[10]="a href='#'项目一/a| a href='#'项目二/a"

links[11]="a href='#'项目一/a | a href='#'项目二/a"

links[12]="a href='#'项目一/a | a href='#'项目二/a"

for (i=0;iliArr.length;i++)

{

liArr[i].onclick=function()

{

selectThis(this,liArr,links)

}

}

}

function selectThis(indexObj,allLi,infoArr)

{

var index=0;

for (i=0;iallLi.length;i++)

{

allLi[i].style.border="1px solid #ffffff";

allLi[i].style.backgroundColor="#86C2FF";

allLi[i].style.height="28px";

if (indexObj==allLi[i])

{

index=i;

}

}

indexObj.style.borderBottom="0px solid #666688";

indexObj.style.backgroundColor="#99cc66";

indexObj.style.height="31px";

document.getElementByIdx_x("subMenu").innerHTML=infoArr[index];

}

/script

body onLoad="ShowMenu()"

div id="dNavBar" style="float:none; width:560px;"li首页/lili娱乐快报/lili音乐天地/lili极品FLASH/li

/div

div id="subMenu"站务公告/div

/body

/html

请教javascript导航栏效果

html

head

style type="text/css"

ul

{

border-bottom:10px solid #efefef;

height:45px;

}

li

{

float:left;

padding:10px 20px;

border-bottom:solid #FFF 3px;

height:22px;

line-height:22px;

overflow:hidden;

}

li:hover, .sel

{

border-bottom:solid #669900 3px;

}

/style

/head

body

ul

li class="sel"首页/li

li测试1/li

li测试2/li

li撒谎测试3/li

li测试4/li

li测试5/li

li测试6/li

li测fdf豆腐干阿萨德试7/li

/ul

/body

/html


标题名称:javascript导航栏,javascript导航栏制作
转载来于:http://cqcxhl.com/article/dsghcgi.html

其他资讯

在线咨询
服务热线
服务热线:028-86922220
TOP