日期:2014-05-16 浏览次数:20338 次
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script type="text/javascript" src="jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
var dd = setInterval(gd, 30);
function gd() {
var position = $(".a").scrollLeft(); //scrollLeft()是获取对象的水平偏移量
if (position < 1000) {
$(".a").scrollLeft(position + 1);
}
else {
$(".a").scrollLeft(0);
}
$("span").html($(".a").scrollLeft()); //显示水平偏移量的值
}
$(".a").mouseleave(function () {
dd = setInterval(gd, 30);
});
$(".a").mouseenter(function () {
clearInterval(dd);
});
});
</script>
<style type="text/css">
* { margin: 0; padding: 0; }
ul { list-style: none; }
li { float: left; margin-left: 10px; }
img { width: 100px; height: 100px; }
.a { width: 400px; margin: 0 auto; overflow: hidden; }
.b { width: 3000px; }
</style>
</head>
<body>
<div class="a">
<div class="b">
<ul>