基于jquery的DIV随滚动条滚动而滚动的代码
人气:0
核心代码:
<script type="text/javascript" src="http:/https://img.qb5200.com/download-x/demo.jb51.net/jslib/jquery/jquery-1.7.2.min.js"></script>
<script type="text/javascript">
$(function() {
$(window).scroll(function() {
var top = $(window).scrollTop()+200;
var left= $(window).scrollLeft()+320;
$("#editInfo").css({ left:left + "px", top: top + "px" });
});
});
</script>
<div id="editInfo" style="float:left;width:300px;background-color:#ccc;position:absolute;top:200px;">
<div>用户名:<input type="text" /></div>
<div>密码:<input type="text" /></div>
<div>年龄:<input type="text" /></div>
<div>备注:<input type="text" /></div>
<div><input type="button" value="保存" /></div>
</div>
<div style="height:1500px"></div>
在线演示 http:/https://img.qb5200.com/download-x/demo.jb51.net/js/2012/jquery_demo/jquery_div.html
记得以前写这样的代码比较麻烦,现在有了JQuery简单多了,就几行代码搞定!
复制代码 代码如下:
<script type="text/javascript" src="http:/https://img.qb5200.com/download-x/demo.jb51.net/jslib/jquery/jquery-1.7.2.min.js"></script>
<script type="text/javascript">
$(function() {
$(window).scroll(function() {
var top = $(window).scrollTop()+200;
var left= $(window).scrollLeft()+320;
$("#editInfo").css({ left:left + "px", top: top + "px" });
});
});
</script>
<div id="editInfo" style="float:left;width:300px;background-color:#ccc;position:absolute;top:200px;">
<div>用户名:<input type="text" /></div>
<div>密码:<input type="text" /></div>
<div>年龄:<input type="text" /></div>
<div>备注:<input type="text" /></div>
<div><input type="button" value="保存" /></div>
</div>
<div style="height:1500px"></div>
在线演示 http:/https://img.qb5200.com/download-x/demo.jb51.net/js/2012/jquery_demo/jquery_div.html
记得以前写这样的代码比较麻烦,现在有了JQuery简单多了,就几行代码搞定!
加载全部内容