gpt4 book ai didi

jquery - 带有滚动条的下拉菜单在 iPad 上不起作用

转载 作者:太空宇宙 更新时间:2023-11-04 11:48:48 25 4
gpt4 key购买 nike

在我的导航栏中,我有一个可滚动的下拉列表。一旦用户悬停在它上面,它就会出现,他可以悬停上下滚动以选择一个链接。它在所有桌面浏览器中都能完美运行,但在 iPad 上,一旦显示下拉菜单,它就会卡住,用户无法上下滚动。

这是我使用的 JS:

var 最大高度 = 400;$(函数(){

$(".dropdown > li").hover(function() {

var $container = $(this),
$list = $container.find("ul"),
$anchor = $container.find("a"),
height = $list.height() * 1.1, // make sure there is enough room at the bottom
multiplier = height / maxHeight; // needs to move faster if list is taller

// need to save height here so it can revert on mouseout
$container.data("origHeight", $container.height());

// so it can retain it's rollover color all the while the dropdown is open
$anchor.addClass("hover");

// make sure dropdown appears directly below parent list item
$list
.show()
.css({
paddingTop: $container.data("origHeight")
});

// don't do any animation if list shorter than max
if (multiplier > 1) {
$container
.css({
height: maxHeight,
overflow: "hidden"
})
.mousemove(function(e) {
var offset = $container.offset();
var relativeY = ((e.pageY - offset.top) * multiplier) - ($container.data("origHeight") * multiplier);
if (relativeY > $container.data("origHeight")) {
$list.css("top", -relativeY + $container.data("origHeight"));
};
});
}

}, function() {

var $el = $(this);

// put things back to normal
$el
.height($(this).data("origHeight"))
.find("ul")
.css({ top: 0 })
.hide()
.end()
.find("a")
.removeClass("hover");

});

});

我不知道我是否解释得当(英语不是我的第一语言),但你可以在 https://jsfiddle.net/x7L4zgfk/1/ 上看到我的意思。

最佳答案

复制自 JavaScript - mousemove event not triggered on iPad/iPhone

Just use jquery.event.move. Move events provide an easy way to set up press-move-release interactions on mouse AND touch devices. So you don't have to worry which device your users have.

Source and examples: http://stephband.info/jquery.event.move/

关于jquery - 带有滚动条的下拉菜单在 iPad 上不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30787564/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com