[英]Horizontal scroll bar with right and left arrow keys
I have searched through the questions, but couldn't find a solution for mine.我已经搜索了问题,但找不到适合我的解决方案。 If this question is a duplicate, i am sorry in advance :)
如果这个问题是重复的,我很抱歉 :)
I already asked the theme creator for a solution, but he couldn't give me a fix.我已经向主题创建者询问了解决方案,但他无法给我解决方案。
My question is as following.我的问题如下。
I am using a WordPress Theme called Contrast and now I have created a page like http://contrast.freevision.me/portfolio-page/horizontal-grid-with-scrollbar/我正在使用名为 Contrast 的 WordPress 主题,现在我创建了一个页面,如http://contrast.freevision.me/portfolio-page/horizontal-grid-with-scrollbar/
That page has a custom scrollbar and it is scrollable with the mouse and dragging also works.该页面有一个自定义滚动条,可以用鼠标滚动,也可以拖动。 But how can i make it scroll with the left and right arrow keys?
但是我怎样才能让它用左右箭头键滚动呢?
Do i need to use the jQuery.animate function or is there a more simpeler solution?我需要使用 jQuery.animate 函数还是有更简单的解决方案?
This is the code i use for adding the right arrow key.这是我用于添加右箭头键的代码。 I can see in the text 'right pressed' in console, but nothing happens.
我可以在控制台中的文本“右键按下”中看到,但没有任何反应。 I tried different classes, but the animate won't trigger.
我尝试了不同的课程,但动画不会触发。 How can i make the scrollbar move a little to the right everytime i press the right arrow?
每次按向右箭头时,如何使滚动条向右移动一点?
jQuery(document).keydown(function(e){
if ((e.keyCode || e.which) == 39)
{console.log('right pressed')}
{
jQuery("div#horizontalGridFolioContainer.horizontal-grid-folio-portfolio.div.div.div").animate({ left: "-=10px" })
}
}); });
I know I'm late but this can be helpful我知道我迟到了但这可能会有所帮助
let scroll_length = 40;
/*Scroll left right*/
$(document).on('keydown',function (e) {
if (e.keyCode === 37) {
element_scroller_wrapper.scrollLeft -= scroll_length;
console.log('<--')
}else if (e.keyCode === 39) {
element_scroller_wrapper.scrollLeft += scroll_length;
console.log('-->')
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.