scrollLeft() trong jQuery
Miêu tả
Phương thức scrollLeft() trong jQuery nhận scrollleft offset của phần tử đã so khớp đầu tiên.
Phương thức này làm việc với cả phần tử nhìn thấy và bị ẩn.
Cú pháp
Sau đây là cú pháp cho scrollLeft() trong jQuery:
selector.scrollLeft( )
Tham số
Dưới đây miêu tả chi tiết về các tham số được sử dụng trong phương thức scrollLeft() trong jQuery:
NA
Ví dụ
Sau đây là ví dụ đơn giản minh họa cách sử dụng của phương thức scrollLeft() trong jQuery:
<html>
<head>
<title>The jQuery Example</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script type="text/javascript" language="javascript">
$(document).ready(function(){
$("div.demo").scrollLeft( 200 );
$("div.demo").mousemove(function () {
var left = $("div.demo").scrollLeft();
$("#result").html("left offset: <span>" + left + "</span>.");
});
});
</script>
<style>
div.demo {background:#CCCCCC none repeat scroll 0 0; border:3px solid #666666; margin:5px; padding:5px; position:relative; width:200px; height:100px; overflow:auto;}
div.result{margin:10px; width:100px; height:100px; margin:5px; float:left; background-color:blue;}
p { margin:10px; padding:5px; border:2px solid #666; width:1000px; height:1000px;}
</style>
</head>
<body>
<div class="demo"><p>Hello</p></div>
<span>Scroll horizontal button to see the result:</span>
<div class="result"><span id="result"></span></div>
</body>
</html>
Nó sẽ cho kết quả:
Công cụ giáo viên (2048.VN)
Tạo- trộn đề thi miễn phí từ file PDF, Word, Giao bài nhanh chóng, Hoàn toàn Free
Các bài học jQuery khác tại VietJack:
Dành cho bạn
Công cụ giáo viên
- Tạo đề online từ PDF / Word
- Trộn nhiều mã đề, in Offline
- Giao bài online, Quản lí lớp học

