我正在寻找一种基于锚点水平制作DIV动画的简单方法。如果可能的话,我宁愿不为此下载整个库......
任何人都可以建议我学习其内部运作的资源吗?
感谢所有人:)
答案 0 :(得分:1)
<div style="width: 200px; height: 100px; overflow: scroll; white-space: nowrap">
FOO FOO FOO FOO FOO FOO FOO FOO FOO FOO FOO FOO FOO FOO FOO FOO
FOO FOO FOO FOO FOO FOO FOO FOO FOO FOO FOO FOO FOO FOO FOO FOO
<span id="a1">BAR!</span>
FOO FOO FOO FOO FOO FOO FOO FOO FOO FOO FOO FOO FOO FOO FOO FOO
</div>
<a href="#a1">scroll to bar (HTML anchor)</a>
<input type="button" value="scroll to bar (JS scrollIntoView)" />
<input type="button" value="scroll to bar (JS scrollLeft)" />
<script type="text/javascript">
var a1= document.getElementById('a1');
var buttons= document.getElementsByTagName('input');
buttons[0].onclick= function() {
a1.scrollIntoView();
};
buttons[1].onclick= function() {
a1.parentNode.scrollLeft= a1.offsetLeft;
};
</script>