快上网专注成都网站设计 成都网站制作 成都网站建设
成都网站建设公司服务热线:028-86922220

网站建设知识

十年网站开发经验 + 多家企业客户 + 靠谱的建站团队

量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决

javascript悬浮,js悬浮固定位置

JS悬浮窗口如何实现

jsp中:

创新互联是一家专注于网站设计制作、成都做网站与策划设计,延吉网站建设哪家好?创新互联做网站,专注于网站建设十年,网设计领域的专业建站公司;建站业务涵盖:延吉等地区。延吉做网站价格咨询:18980820575

body

div style="position: absolute;z-index:90" id="div1"我不动/div

div我动div

/body

//有的将position设置成fixed,我试了试效果不如position好,设置z-index,向里的深度,我这儿设置90,你要覆盖几个div,设置数大于那个数就行。

js中:

我这儿用jquery写。

$(document).ready(function(){

$(window).scroll(function(){//滚动时触发函数

$("#div1").css("top",$(document).scrollTop());//将滚动条高度赋给悬浮框。

})

})

导入jquery库,效果就出来了。

JavaScript如何实现悬浮层

效果如图

html

head

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

title学生信息系统/title

script language="javascript"

var showInfo = new function () {

this.showLayer = function (e, id) {

var p = window.event ? [event.clientX, event.clientY] : [e.pageX, e.pageY];

with (document.getElementById(id + "").style) {

display = "block";

left = p[0] + 10 + "px";

top = p[1] + 10 + "px";

}

if (window.event) {

window.event.cancelBubble = true;

} else {

if (e) {

e.preventDefault();

}

}

};

this.hideLayer = function (e, id) {

with (document.getElementById(id + "").style) {

display = "none";

}

if (window.event) {

window.event.cancelBubble = true;

} else {

if (e) {

e.preventDefault();

}

}

};

};

/script

style type="text/css"

.helplay {

z-index: 3;

position: absolute;

border: 1px solid #FFC30E;

padding: 5px;

background-color: #FFFBB8;

text-align: left;

color: #9C7600;

width: 130px;

font-size: 15px;

font-family: arial, sans-serif;

}

/style

/head

body

table width="760" border="0" align="center"

tr

td width="20%" height="46"/td

td width="60%" align="center"

学生信息系统

/td

td width="20%"/td

/tr

tr

td width="20%" height="272" align="center"/td

td align="center"

table

tr

div style="display: none" id="C1320" class="helplay"

学号:222222br

年龄:18br

班级:2br

专业:软开br

学院:软件学院

/div

/tr

tr

td bgcolor="#ffffaa" rowspan=2姓名

/td

td colspan="2" bgcolor="#ffffaa"

div id="C13" href="#"

onmouseover="return showInfo.showLayer(event,'C1320');"

onmouseout="return showInfo.hideLayer(event,'C1320');"

b张三/b

/div

/td

td bgcolor="#ffffaa" rowspan=2

待定

/td

/tr

tr

div style="display: none" id="C1220" class="helplay"

学号:1111br

年龄:28br

班级:1br

专业:软开br

学院:软件学院

/div

/tr

tr

td bgcolor="#ffffaa" rowspan=2姓名

/td

td colspan="2" bgcolor="#ffffaa"

div id="C12" href="#"

onmouseover="return showInfo.showLayer(event,'C1220');"

onmouseout="return showInfo.hideLayer(event,'C1220');"

b李四/b

/div

/td

td bgcolor="#ffffaa" rowspan=2

待定

/td

/tr

/table

/td

td width="20%" align="center"/td

/tr

/table

/body

/html

javascript如何默认控件悬浮

用JavaScript隐藏控件的方法有两种,分别是通过设置控件的style的“display”和“visibility”属性。当style.display="block"或style.visibility="visible"时控件或见,当style.display="none"或style.visibility="hidden"时控件不可见。不同的是“display”不但隐藏控件,而且被隐藏的控件不再占用显示时占用的位置,而“visibility”隐藏的控件仅仅是将控件设置成不可见了,控件仍然占俱原来的位置。

function displayHideUI()

{

var ui =document.getElementById("bbs");

ui.style.display="none";

}

function displayShowUI()

{

var ui =document.getElementById("bbs");

ui.style.display="";//display为空的话会好使,为block会使后边的空间换行

}

function visibilityHideUI()

{

var ui =document.getElementById("bbs");

ui.style.visibility="hidden";

}

function visibilityShowUI()

{

var ui =document.getElementById("bbs");

ui.style.visibility="visible";

}

/script

值 描述

none 此元素不会被显示。

block 此元素将显示为块级元素,此元素前后会带有换行符。

inline 默认。此元素会被显示为内联元素,元素前后没有换行符。

inline-block 行内块元素。(CSS2.1新增的值)

list-item 此元素会作为列表显示。

run-in 此元素会根据上下文作为块级元素或内联元素显示。

compact CSS 中有值compact,不过由于缺乏广泛支持,已经从CSS2.1 中删除。

marker CSS 中有值marker,不过由于缺乏广泛支持,已经从CSS2.1 中删除。

table 此元素会作为块级表格来显示(类似table),表格前后带有换行符。

inline-table 此元素会作为内联表格来显示(类似table),表格前后没有换行符。

table-row-group 此元素会作为一个或多个行的分组来显示(类似tbody)。

table-header-group 此元素会作为一个或多个行的分组来显示(类似thead)。

table-footer-group 此元素会作为一个或多个行的分组来显示(类似tfoot)。

table-row 此元素会作为一个表格行显示(类似tr)。

table-column-group 此元素会作为一个或多个列的分组来显示(类似colgroup)。

table-column 此元素会作为一个单元格列显示(类似col)

table-cell 此元素会作为一个表格单元格显示(类似td和th)

table-caption 此元素会作为一个表格标题显示(类似caption)

inherit 规定应该从父元素继承display属性的值。

今天解决的问题是在jsp页面中给css定义的label.error的类一个id,然后通过控制id的可见性来实现收起div时清除js的提示信息。具体如下:

在准备界面的函数中var label1 = document.getElementById("label1");

$(document).ready(function() {

$(".flipp .span4").click(function() {

$(this).parent().next().toggle();

$(this).parent().parent().prevAll().find(".panel").hide();

$(this).parent().parent().nextAll().find(".panel").hide();

var label1 = document.getElementById("label1");

label1.style.display="none";

})

然后在jsp相应的地方加入:

label class="error" id="label1" for="currentPWD" generated="true" style="display:inline"/label

对于css定义的label.error类,可以使用$("label.error").removeAttr("style").attr("style", "display: none;");来实现如上的功能。。。。。而且,貌似也不用在地下相应的位置给label定义id值


当前名称:javascript悬浮,js悬浮固定位置
分享地址:http://6mz.cn/article/dsdddoj.html

其他资讯