首页 > 编程 > JavaScript > 正文

基于jquery的DIV随滚动条滚动而滚动的代码

2019-11-20 23:19:56
字体:
来源:转载
供稿:网友
核心代码:
复制代码 代码如下:

<script type="text/javascript" src="http://demo.VeVB.COm/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://demo.VeVB.COm/js/2012/jquery_demo/jquery_div.html
记得以前写这样的代码比较麻烦,现在有了JQuery简单多了,就几行代码搞定!
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表