❶ 如何用js实现鼠标划过SVG中的元素 弹出DIV层
onmousemove 必须写在svg中,但svg中无法识别html的div标签,我试了一下 可以alert信息。但不能加载HTML元素
别用embed。直接用svg嵌进去试试。
❷ js弹出div并显示遮罩层
弹出div显示遮罩层的效果,想必大家都有见到过吧,下面有个示例,大家可以参考下
代码如下:
//--------------------弹出层-------------------
//popDivId:弹出层div的ID
//dragDivId:用于拖动div的ID
//isShowMask:是否显示遮罩层
function
popDivShow(popDivId,
dragDivId,
isShowMask)
{
if
(isShowMask)
{
creatMask(popDivId);
}
var
oWins
=
document.getElementById(popDivId);
var
oWins_title
=
document.getElementById(dragDivId);
var
bDrag
=
false;
var
disX
=
disY
=
0;
oWins.style.display
=
"block";
oWins_title.onmousedown
=
function(event)
{
var
event
=
event
||
window.event;
bDrag
=
true;
disX
=
event.clientX
-
oWins.offsetLeft;
disY
=
event.clientY
-
oWins.offsetTop;
this.setCapture
&&
this.setCapture();
return
false;
};
document.onmousemove
=
function(event)
{
if
(!bDrag)
return;
var
event
=
event
||
window.event;
var
iL
=
event.clientX
-
disX;
var
iT
=
event.clientY
-
disY;
var
maxL
=
document.documentElement.clientWidth
-
oWins.offsetWidth;
var
maxT
=
document.documentElement.clientHeight
-
oWins.offsetHeight;
iL
=
iL
<
0
?
0
:
iL;
iL
=
iL
>
maxL
?
maxL
:
iL;
iT
=
iT
<
0
?
0
:
iT;
iT
=
iT
>
maxT
?
maxT
:
iT;
oWins.style.marginTop
=
oWins.style.marginLeft
=
0;
oWins.style.left
=
iL
+
"px";
oWins.style.top
=
iT
+
"px";
return
false;
};
document.onmouseup
=
window.onblur
=
oWins_title.onlosecapture
=
function()
{
bDrag
=
false;
oWins_title.releaseCapture
&&
oWins_title.releaseCapture();
};
}
//
隐藏弹出层
function
popDivHidden(popDivId)
{
var
oWins
=
document.getElementById(popDivId);
oWins.style.display
=
"none";
window.parent.document.body.removeChild(window.parent.document.getElementById("maskDiv"));
}
//
获取弹出层的zIndex
function
getZindex(popDivId)
{
var
popDiv
=
document.getElementById(popDivId);
var
popDivZindex
=
popDiv.style.zIndex;
return
popDivZindex;
}
//
创建遮罩层
function
creatMask(popDivId)
{
//
参数w为弹出页面的宽度,参数h为弹出页面的高度,参数s为弹出页面的路径
var
maskDiv
=
window.parent.document.createElement("div");
maskDiv.id
=
"maskDiv";
maskDiv.style.position
=
"fixed";
maskDiv.style.top
=
"0";
maskDiv.style.left
=
"0";
maskDiv.style.zIndex
=
getZindex(popDivId)
-
1;
maskDiv.style.backgroundColor
=
"#333";
maskDiv.style.filter
=
"alpha(opacity=70)";
maskDiv.style.opacity
=
"0.7";
maskDiv.style.width
=
"100%";
maskDiv.style.height
=
(window.parent.document.body.scrollHeight
+
50)
+
"px";
window.parent.document.body.appendChild(maskDiv);
maskDiv.onmousedown
=
function()
{
window.parent.document.body.removeChild(window.parent.document.getElementById("maskDiv"));
};
}
❸ 点击一个div图层,在其上面弹出另一个div图层,用js怎么实现
两个div先写好,一个先隐藏,点击后更改其属性,让其显示
<!doctypehtml>
<htmllang="en">
<head>
<metacharset="UTF-8">
<title>Document</title>
<style>
.outer{
position:relative;
height:300px;
width:500px;
background-color:#097df3;
}
.d1{
display:none;
position:absolute;
height:200px;
width:300px;
top:50px;
left:100px;
background-color:#FF6C00;
}
</style>
</head>
<body>
<divclass="outer"onclick="fn()">
<divclass="d1"></div>
</div>
<script>
functionfn(){
document.getElementsByClassName('d1')[0].style.display="block";
}
</script>
</body>
</html>
❹ html如何用JS自动弹出一个DIV
也就先做一个DIV。里面的内容都做好。
此DIV背后加一个mask层。
把这个DIv默认设置为隐藏。
JS里加一个定时器,每隔一分钟,设置为这个DIv的css样式中的display=block
❺ JS弹出DIV窗口,按ESC取消
显示层:
css:
.showdiv
{
width: 100%;
height: auto;
position: absolute;
left: 0;
top: 0;
z-index: 999;
display: none;
}
.count_div
{
width: 500px;
height: 400px;
margin-top: 120px;
margin-left: auto;
margin-right: auto;
margin-bottom: 0;
border: 1px solid #aaaaaa;
background: #fff;
}
.brg
{
width: 100%;
background: #ededed;
position: absolute;
top: 0;
left: 0;
filter: alpha(opacity=60);
-moz-opacity: 0.6;
opacity: 0.6;
position: absolute;
top: 0;
left: 0;
display: none;
z-index: 998;
}
js:
function close () {
$("#brg").css("display", "none");
$("#showdiv").css("display", "none");
}
function show() {
$("#brg").css("display", "none");
$("#div_show").css("display", "none");
}
$(document).bind('keydown', 'esc',function (evt){
//关闭层代码
close () ;
return false; });
html:
<!--遮罩层-->
<div class="brg" id="brg">
</div>
<!--显示层-->
<div class="showdiv" id="div_order">
<div class="count_div" id="div_order_count">
内容
</div>
</div>
在网上找一个“jquery.hotkeys.js”的js包,里面都是jquery整理好的热键,
引入jquery包。
$(document).bind('keydown', 'esc',function (evt){
//关闭层代码
return false; });
手敲,未测试,应该不会有太大问题,根据自己内容修改
❻ JS如何实现点击文本框弹出DIV层
if (!getobj(inputid+"mydiv")){//若尚未创建就建之
var divcss="font-size:12px;color:#00f;position:absolute;left:"+(getobj(inputid).offsetLeft+0)+"px;top:"+(getobj(inputid).offsetTop+25)+"px;border:1px solid red"
crertdiv("","div",inputid+"mydiv",divcss);//创建层"mydiv"
//alert(document.getElementById("mydiv").outerHTML)
crertdiv(inputid+"mydiv","ul",inputid+"myul");//创建ul
for (var i=0,j=text_list.length;i<j;i++){//创建"text_list"li
crertdiv(inputid+"myul","li",inputid+"li"+i,"background:#fff");
getobj(inputid+"li"+i).innerHTML=text_list;}crertdiv(inputid+"myul","li",inputid+"li"+j,"color:#f00;background:#fff");//创建"clear"li
getobj(inputid+"li"+j).innerHTML="clear";
getobj(inputid+"mydiv").innerHTML +="<style type='text/css'#"+inputid+"mydiv ul {padding:0px;margin:0;}#"+inputid+"mydiv ul li{list-style-type:none;padding:5px;margin:0;float:left;cursor: pointer;}</style"
for (var i=0;i<=j;i++){
getobj(inputid+"li"+i).onmouseover=function(){this.style.background="#eee";clearTimeout(timer)}
getobj(inputid+"li"+i).onmouseout=function(){this.style.background="#fff"}}}var newdiv=getobj(inputid+"mydiv")
newdiv.onclick=function(){hiddiv(event,inputid);}
newdiv.onmouseout=function(){Mout(this)}
newdiv.onmouseover=function(){clearTimeout(timer)}
getobj(inputid).onmouseout=function(){Mout(newdiv)}
newdiv.style.display="block";swtemp=1;objtemp=inputid;}var timerfunction Mout(o){
timer=setTimeout(function(){o.style.display="none";},300)swtemp=0;}function hiddiv(e,inputid){
e=e||window.event;
ev=e.target||e.srcElement;
v=ev.innerText||ev.textContent;
if (v!="clear")getobj(inputid).value=v;else getobj(inputid).value=""
getobj(inputid+"mydiv").style.display="none";}</script</head<body
....利用定义标签赋值....(onclick)....<input id="mytext" type="text"onclick="showdiv(this.id,this.list)" list="文本框,弹出层,值赋"/<scriptvar list="文本框2,弹出层2,值赋2,文本框2-1,弹出层2-1,值赋2-1"
</script
....利用定义js变量赋值...(onclick)....<input id="mytext2" type="text" onClick="showdiv(this.id,list)"/
<input type="hidden" value="点击,弹出,显示,消失,实现" id="list"
....利用隐藏域值赋值....(onmouseover).....<input id="mytext3" type="text" onMouseOver="showdiv(this.id,getobj('list').value)"/</body</html
❼ 点击js弹出div层,当鼠标移出div层窗口后任意点击关闭div层窗口!大虾们应该怎么实现啊啊啊
div对象.onclick=function(ev){ev = ev || window.event; ev.cancelBubble = true;}
document.documentElement.onclick=function(ev){这里写关闭div的代码}
不懂再问我
❽ 如何js弹出div
js如下:
<script language="javascript">
//登陆弹出对话框,并使背景元素不可用
var div_width = 300;
var div_height = 200;
function showWindow(width,height){
location.href="#";
width = div_width;
height = div_height
var windowstr= document.getElementById("popLayer").innerHTML;
document.getElementById("infoDiv").innerHTML=windowstr;
document.getElementById("infoDiv").style.left=((document.body.clientWidth-width)>0?(document.body.clientWidth-width):0)/2+"px";
document.getElementById("infoDiv").style.top=200+"px";
document.getElementById("infoDiv").style.zIndex=10001;
document.getElementById("infoDiv").style.width=width;
document.getElementById("infoDiv").style.height=height;
document.getElementById("infoDiv").style.border="3px solid #0099ff";
document.getElementById("tranDiv").style.height=document.body.clientHeight+ "px";
document.getElementById("tranDiv").style.width=document.body.clientWidth+ "px";
document.getElementById("tranDiv").style.display="";
document.getElementById("tranDivBack").style.display="";
document.getElementById("tranDivBack").style.zIndex=10000;
document.getElementById("infoDiv").style.display="";
}
function closeWindow(){
document.getElementById("tranDiv").style.display="none";
}
</script>
页面中:
<!--层遮罩部分-->
<div style="position:absolute;display:none; left:0px; top:0px;" id="tranDiv">
<div style="position:absolute;left:0px; top:0px; width:100%; height:100%;background-color:#000000;filter:alpha(Opacity=30)" id="tranDivBack"> </div>
<div align='center'style='position:absolute;left:0px; top:0px; width:100%; height:100%; background-color:#e5edf5;background-image:url(images/bestnetqywimg/tccbg.gif);' id='infoDiv'></div>
</div>
<!--层遮罩部分结束-->
<!--弹出层登录-->
<div id="popLayer" style="display:none"><form id="formdl" name="formdl" method="post" action=""><br /><font align="center" color="#0000ff" size="3"><b>---手机号码先登录---</b></font><br /><br />
<br/>
<input type="submit" name="Submit" class="bntccanniu" value="登录" /> <input type="button" name="Submit1" class="bntccanniu" value="取消" onclick="closeWindow();"/>
</form>
</div>
<a href="javascript:;">点击此处看看</a>