已掉线,重新登录

首页 > 绿虎论坛 > 历史版块 > 编程 > HTML/CSS/JS

标题: JS拖动层(简洁,兼容ie)

作者: @Ta

时间: 2016-10-09发布,2016-10-09修改

点击: 2094

在ie中拖动会选定文本,只兼容电脑.ff、opera、safari、Chrome
<div id="f" style="background-color:#FFF;border:solid 1px #08C;position:fixed;top:0px;left:0px;z-index:101;">
<div id="title" style="background-color:#08C;cursor:move;height:5px;"></div>
<a href="javascript:scroll(0,0)"title="回顶↑">TOP</a>
</div><div style="padding-top:25px"></div>
<script type="text/javascript">
var posX;
var posY;       
fdiv = document.getElementById("f");           
document.getElementById("title").onmousedown=function(e)
{
    if(!e) e = window.event;  //IE
    posX = e.clientX - parseInt(fdiv.style.left);
    posY = e.clientY - parseInt(fdiv.style.top);
    document.onmousemove = mousemove;           
}
document.onmouseup = function()
{
    document.onmousemove = null;
}
function mousemove(ev)
{
    if(ev==null) ev = window.event;//IE
    fdiv.style.left = (ev.clientX - posX) + "px";
    fdiv.style.top = (ev.clientY - posY) + "px";
}
</script>


可以在网页插件中测试

[隐藏样式|查看源码]


『回复列表(1|隐藏机器人聊天)』

1. 用插件不是更好?
(/@Ta/2016-10-09 08:57//)

回复需要登录

9月28日 07:31 星期天

本站由hu60wap6驱动

备案号: 京ICP备18041936号-1