3
我正在尝试使用左/右箭头在我的网页上水平导航。KeyPress水平导航
由于Firefox/Chrome以不同方式处理默认箭头移动,我不得不禁用默认移动(Firefox会将它移动20px太远)。
<script>
window.addEventListener("keydown", function(e) {
// space and arrow keys
if([32, 37, 38, 39, 40].indexOf(e.keyCode) > -1) {
e.preventDefault();
}
}, false);
</script>
我得到了一个Keydown函数,可以在按键上移动1980px左/右。 (我coudln't得到按键,因为阻止默认此举的工作),我希望它是经常性(的页面是6000px宽)
<script>
$(window).keydown(function (e) {
var currentx = 0;
var viewport = 1920;
var btnright = (+currentx) + (+viewport);
var btnleft = (+currentx) - (-viewport);
if (e.which == 37) {
window.scrollTo(btnleft, 0);
currentx = (+currentx) - (-viewport);
} else if (e.which == 39) {
window.scrollTo(btnright, 0);
currentx = (+currentx) + (+viewport);
}
});
</script>
但我想一次移动1个面板(1980px)(每次移动后更新$ Current)。最终,我可以通过箭头浏览整个页面。
我的问题是我不能让事件触发不止一次,我只能从0到1980导航。它不会再继续。有没有解决这个问题?
感谢
我不认为这是事件的问题被触发一次(放置的console.log调试输出在开始时_verify_) ,而是每次调用处理程序时都要将'currentx'设置为'0'。 – CBroe