jQuery中scrollLeft()方法用法實例
本文實例講述了jQuery中scrollLeft()方法用法。分享給大家供大家參考。具體分析如下:
此方法獲取或設置匹配元素相對滾動條左側的偏移(offset)量。
語法結構一:
當scrollLeft()方法沒有參數(shù)的時候就是獲取匹配元素相對滾動條左側的偏移量。
實例代碼:
<!DOCTYPE html>
<html>
<head>
<meta charset=" utf-8">
<meta name="author" content="http://www.dbjr.com.cn/" />
<title>腳本之家</title>
<style type="text/css">
#div1{
border:1px solid black;
width:200px;
height:200px;
overflow:auto
}
#div2{
height:150px;
width:400px;
}
#div3{
height:40px;
width:200px;
background-color:green;
}
</style>
<script type="text/javascript" src="mytest/jQuery/jquery-1.8.3.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("button").click(function(){
alert($("#div1").scrollLeft());
});
})
</script>
</head>
<body>
<div id="div1">
<div id="div2">
<div id="div3"></div>
</div>
</div>
<button>獲取offset值</button>
</body>
</html>
語法結構二:
當scrollLeft()帶有參數(shù)的時候是設置匹配元素相對滾動條左側的偏移量。
參數(shù)列表:
實例代碼:
<!DOCTYPE html>
<html>
<head>
<meta charset=" utf-8">
<meta name="author" content="http://www.dbjr.com.cn/" />
<title>腳本之家</title>
<style type="text/css">
#div1{
border:1px solid black;
width:200px;
height:200px;
overflow:auto
}
#div2{
height:150px;
width:400px;
}
#div3{
height:40px;
width:200px;
background-color:green;
}
</style>
<script type="text/javascript" src="mytest/jQuery/jquery-1.8.3.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("button").click(function(){
$("#div1").scrollLeft(100);
});
});
</script>
</head>
<body>
<div id="div1">
<div id="div2">
<div id="div3"></div>
</div>
</div>
<button>設置offset值</button>
</body>
</html>
希望本文所述對大家的jquery程序設計有所幫助。
本文轉自:螞蟻部落http://www.softwhy.com/
- 淺談jQuery頁面的滾動位置scrollTop、scrollLeft
- jQuery 位置函數(shù)offset,innerWidth,innerHeight,outerWidth,outerHeight,scrollTop,scrollLeft
- jquery計算鼠標和指定元素之間距離的方法
- jquery計算出left和top,讓一個div水平垂直居中的簡單實例
- 用Jquery選擇器計算table中的某一列某一行的合計
- 一個簡單的jQuery計算器實現(xiàn)了連續(xù)計算功能
- jQuery實現(xiàn)購物車多物品數(shù)量的加減+總價計算
- jQuery 計算iframe 窗口大小的方法
- jQuery計算textarea中文字數(shù)(剩余個數(shù))的小程序
- 基于jQuery的計算文本框字數(shù)的代碼
- jQuery居中元素scrollleft計算方法示例
相關文章
兼容主流瀏覽器的jQuery+CSS 實現(xiàn)遮罩層的簡單代碼
比起使用注冊頁和登陸頁,網(wǎng)站在當前頁使用遮罩層注冊和登陸的用戶體驗要好不少。這里使用jQuery和CSS實現(xiàn)一個簡單的遮罩效果。2014-10-10jQuery Mobile操作HTML5的常用函數(shù)總結
jQuery Mobile是針對移動端開發(fā)的JavaScript框架,正如其名基于jQuery庫,jQuery Mobile主要被用來操作HTML5設計頁面UI,下面就來看一下jQuery Mobile操作HTML5的常用函數(shù)總結:2016-05-05jQuery中fadeIn、fadeOut、fadeTo的使用方法(圖片顯示與隱藏)
jQuery中fadeIn、fadeOut、fadeTo的使用方法(圖片顯示與隱藏),需要的朋友可以參考一下2013-05-05jQuery實現(xiàn)點擊小圖片淡入淡出顯示大圖片特效
本文給大家分享基于jquery實現(xiàn)的一款圖片特效,當點擊小圖片時會淡入淡出大圖片,通過定義需要展示的圖片以及圖片要展示的時間,來實現(xiàn)這一效果,感興趣的朋友跟著小編一起來學習吧2015-09-09