简体   繁体   English

用户触摸导航元素时的悬停效果

[英]Hover effect when user touches sliding through nav elements

I've implemented a sidebar navigation with a hover effect to jump from slide to slide on a custom slider which is working fine using a simple jQuery hover() function: 我已经实现了带有悬停效果的侧边栏导航,可以在自定义滑块上从幻灯片跳到幻灯片,使用简单的jQuery hover()函数可以正常工作:

$('#slider-nav ul li').hover(function() {
  $(this).prev().addClass('hover-sib');
  $(this).next().addClass('hover-sib');
}, function(e) {
  $(this).prev().removeClass('hover-sib');
  $(this).next().removeClass('hover-sib');
});

but on mobile it would need to be polished. 但在移动设备上则需要进行抛光。

The idea is to have the same hover effect on real time while the user slides the finger vertically over the lines, making them grow to the side and the text to appear. 想法是实时地具有相同的悬停效果,同时用户将手指垂直滑过线,使其长到一边并显示文本。 Once the user releases on an option it could be interesting to call that slide, but that is not the priority right now. 用户释放某个选项后,调用该幻灯片可能会很有趣,但这并不是当前的优先事项。 The bigger issue is how to achieve the similar effect of a hover when a user slide the finger through the element... 更大的问题是当用户将手指滑过元素时如何实现悬停的类似效果...

Any idea? 任何想法? I thought on using 'touchmove' but I don't think that I could tell if the user is over one of those options or even which one of them. 我曾考虑使用'touchmove',但我不认为我可以判断用户是否选择了其中一个选项,甚至选择了其中一个选项。

$('#slider-nav ul li').bind('touchmove',function(){
    $(this).prev().addClass('hover-sib');
    $(this).next().addClass('hover-sib');
});

Sample: https://jsfiddle.net/ac_coding/d7xnndg2/ 范例: https//jsfiddle.net/ac_coding/d7xnndg2/


UPDATE : In case it wasn't properly understood/explained, what I'm trying to achieve here is the same hover effect on a desktop when a mobile user touches the screen and, without lifting the finger, moves from along the vertical right edge, hovering and passing through different lines/options of the nav which would be triggering their "hover" effect. 更新 :如果未正确理解/解释,我在这里想要实现的效果是,当移动用户触摸屏幕并且无需抬起手指而沿垂直的右边缘移动时,桌面上的悬停效果相同,悬停并通过导航的不同行/选项,这将触发其“悬停”效果。 Using touchstart/touchend will require the user to tap at different points of the nav in order to see the options. 使用touchstart / touchend将要求用户在导航的不同点处点击以查看选项。

I hope it makes sense, doesn't seem easy to explain :S 我希望这很有意义,似乎不太容易解释:S


UPDATE 2 : It seems that I finally found a solution but I don't have the time now. 更新2 :似乎我终于找到了解决方案,但现在没有时间。 I'll update this question tomorrow explaining it for everyone else. 我明天将更新此问题,并为其他所有人解释。 Thanks everybody for your help! 谢谢大家的帮助!

Did you try to bind to the touch event? 您是否尝试绑定触摸事件? You need to add "hover-effect" class (where :hover styles are) as your additional CSS selector as well. 您还需要添加“ hover-effect”类(其中:hover样式)作为附加的CSS选择器。

$('#slider-nav ul li').bind('touchstart', function() {
  $(this).addClass('hover-effect');
  $(this).prev().addClass('hover-sib');
  $(this).next().addClass('hover-sib');
});

$('#slider-nav ul li').bind('touchend', function() {
  $(this).removeClass('hover-effect');
  $(this).prev().removeClass('hover-sib');
  $(this).next().removeClass('hover-sib');
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM