我的问题解决起来应该很简单,我希望能够正确地跨浏览器运行。我想有一个带有overflow-x的水平滚动条:滚动和溢出-y:隐藏对齐自己在指定的.scrollLeft位置,并刷新我的网站。
我想出了:
<head>
<script type="text/javascript">
$(window).load(function(){
$('outside, html').scrollLeft (100);
});
</script>
<style type="text/css">
div#outside {
width: 100%;
overflow-x: scroll;
overflow-y: hidden;
}
div#inside { width: 500px; }
</style>
</head>
<body>
<div id="outside">
<div id="inside">A bunch of text here...
</div>
</div>
</body>
我找到了一个JSFiddle作为模板用于我的尝试但是当我在Dreamweaver浏览器(safari,chrome,firefox)中预览时它不起作用。我很确定这是一个简单的解决方案,如果有人可以提供帮助,那将非常感激。谢谢!
答案 0 :(得分:0)
我认为你必须使用window.onload事件,你可以像这样使用..
HTML
<body onload="myFunction()">
<div id="foo">
<div id="bar">
Hello world. Hello world. Hello world. Hello world. Hello world. Hello world. Hello world. Hello world. Hello world. Hello world. Hello world. Hello world. Hello world. Hello world. Hello world. Hello world. Hello world. Hello world. Hello world. Hello world. Hello world. Hello world. Hello world. Hello world. Hello world. Hello world. Hello world. Hello world. Hello world. Hello world. Hello world. Hello world. Hello world. Hello world. Hello world. Hello world. Hello world. Hello world. Hello world. Hello world. Hello world. Hello world. Hello world. Hello world. Hello world. Hello world. Hello world. Hello world. Hello world. Hello world. Hello world. Hello world. Hello world. Hello world. Hello world. Hello world. Hello world. Hello world. Hello world. Hello world. Hello world. Hello world. Hello world. Hello world. Hello world. Hello world. Hello world. Hello world. Hello world. Hello world. Hello world. Hello world. Hello world. Hello world. Hello world. Hello world. Hello world. Hello world. Hello world. Hello world. Hello world. Hello world. Hello world. Hello world. Hello world. Hello world. Hello world. Hello world. Hello world. Hello world. Hello world.
</div>
</div>
</body>
JAVASCRIPT
<script type="text/javascript">
function myFunction(){
document.getElementById('foo').scrollLeft = 500;
}
</script>
答案 1 :(得分:0)
试试这个。
//$( "#foo" ).scrollLeft( 500 ); // Without animation
$("#foo").animate({scrollLeft:500}) // With animation