JQuery Div层滚动条控制(模拟横向滚动条在最顶端显示)

想让DIV层滚动条显示在顶端,CSS样式没找到相关属性,于是用2个DIV层来模拟做了一个。
经测试IE浏览器上显示并不太美观!不知道是否还有更好的办法可以实现这功能呢?

 
aaaaaaasssssssdddddddfffffffgggggggghhhhhhhhhjjjjjjjjkkkkkkkkllllllllll
aaaaaaasssssssdddddddfffffffgggggggghhhhhhhhhjjjjjjjjkkkkkkkkllllllllll
aaaaaaasssssssdddddddfffffffgggggggghhhhhhhhhjjjjjjjjkkkkkkkkllllllllll

 

<!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 src="Scripts/jquery-1.4.1.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(function () {
            $("#div2").css("overflow-x", "scroll").height(16).width($("#div1").width()+20); //设置一个高度10的DIV2层 长度与DIV1层一致
            $("#div2").html($("#div1").html()); //并给DIV2层填充内容

            $("#div2").scroll(function () {
                $("#div1")[0].scrollLeft = $("#div2")[0].scrollLeft; //拉动DIV2层滚动条,DIV1层滚动条同步被改变
            });
        });
    </script>
</head>
<body>
<p></p>
<div id="div2"></div>
<div id="div1" style="border-style: solid; border-width: 1px; border-color: inherit; width:150px; height:120px; overflow-x:scroll; ">
aaaaaaasssssssdddddddfffffffgggggggghhhhhhhhhjjjjjjjjkkkkkkkkllllllllll<br />
aaaaaaasssssssdddddddfffffffgggggggghhhhhhhhhjjjjjjjjkkkkkkkkllllllllll<br />
aaaaaaasssssssdddddddfffffffgggggggghhhhhhhhhjjjjjjjjkkkkkkkkllllllllll<br />
</div>
</body>
</html>

 

posted @ 2013-08-03 01:06  hg一如既往  阅读(7573)  评论(0编辑  收藏  举报