基于jquery的DIV隨滾動條滾動而滾動的代碼
更新時間:2012年07月20日 18:56:57 作者:
基于jquery的DIV隨滾動條滾動而滾動的代碼,有了JQuery簡單多了,就幾行代碼搞定
核心代碼:
<script type="text/javascript" src="http://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://demo.jb51.net/js/2012/jquery_demo/jquery_div.html
記得以前寫這樣的代碼比較麻煩,現(xiàn)在有了JQuery簡單多了,就幾行代碼搞定!
復(fù)制代碼 代碼如下:
<script type="text/javascript" src="http://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://demo.jb51.net/js/2012/jquery_demo/jquery_div.html
記得以前寫這樣的代碼比較麻煩,現(xiàn)在有了JQuery簡單多了,就幾行代碼搞定!
您可能感興趣的文章:
- js/jquery獲取瀏覽器窗口可視區(qū)域高度和寬度以及滾動條高度實現(xiàn)代碼
- JQuery獲取元素文檔大小、偏移和位置和滾動條位置的方法集合
- jQuery scroll事件實現(xiàn)監(jiān)控滾動條分頁示例
- jquery easyui滾動條部分設(shè)置介紹
- jquery 判斷滾動條到達(dá)了底部和頂端的方法
- 基于jquery的橫向滾動條(滑動條)
- jQuery 錨點跳轉(zhuǎn)滾動條平滑滾動一句話代碼
- asp.net+jquery滾動滾動條加載數(shù)據(jù)的下拉控件
- JS和JQUERY獲取頁面大小,滾動條位置,元素位置(示例代碼)
- jquery滾動條插件slimScroll使用方法
相關(guān)文章
jQuery對象數(shù)據(jù)緩存Cache原理及jQuery.data方法區(qū)別介紹
jQuery.data(..)來實現(xiàn)數(shù)據(jù)緩存,但有兩個用戶經(jīng)常使用的data([key],[value])和jQuery.data(element,[key],[value]),接下來為大家介紹下他們的區(qū)別,感興趣的朋友可以參考下哈2013-04-04
關(guān)于jquery form表單序列化的注意事項詳解
這篇文章主要給大家介紹了關(guān)于jquery form表單序列化的注意事項,文中通過示例代碼介紹的非常詳細(xì),對大家具有一定的參考學(xué)習(xí)價值,需要的朋友們下面跟著小編來一起學(xué)習(xí)學(xué)習(xí)吧。2017-08-08

