javascript - 将 jqueryslidemenu 从悬停更改为单击
问题描述
我一直在使用在DynamicDrive上找到的脚本
多年来,它运行良好,直到最近我发现菜单在移动设备上不起作用,我注意到我需要将事件从 mouseover 更改为 mouseclick,因为移动设备不使用鼠标。
我尝试将 $curobj.hover(... 更改为 $curobj.click(... 但它不起作用。下面是 jqueryslidemenu.js 的内容
//============================================================================
//Update: April 12th, 10: Fixed compat issue with jquery 1.4x
//Specify full URL to down and right arrow images (23 is padding-right to add to top level LIs with drop downs):
var arrowimages={down:['downarrowclass', '../resources/down.gif', 23], right:['rightarrowclass', '../resources/right.gif']}
var jqueryslidemenu={
animateduration: {over: 200, out: 100}, //duration of slide in/ out animation, in milliseconds
buildmenu:function(menuid, arrowsvar){
jQuery(document).ready(function($){
var $mainmenu=$("#"+menuid+">ul")
var $headers=$mainmenu.find("ul").parent()
$headers.each(function(i){
var $curobj=$(this)
var $subul=$(this).find('ul:eq(0)')
this._dimensions={w:this.offsetWidth, h:this.offsetHeight, subulw:$subul.outerWidth(), subulh:$subul.outerHeight()}
this.istopheader=$curobj.parents("ul").length==1? true : false
$subul.css({top:this.istopheader? this._dimensions.h+"px" : 0})
$curobj.children("a:eq(0)").css(this.istopheader? {paddingRight: arrowsvar.down[2]} : {}).append(
'<img src="'+ (this.istopheader? arrowsvar.down[1] : arrowsvar.right[1])
+'" class="' + (this.istopheader? arrowsvar.down[0] : arrowsvar.right[0])
+ '" style="border:0;" />'
)
$curobj.hover(
function(e){
var $targetul=$(this).children("ul:eq(0)")
this._offsets={left:$(this).offset().left, top:$(this).offset().top}
var menuleft=this.istopheader? 0 : this._dimensions.w
menuleft=(this._offsets.left+menuleft+this._dimensions.subulw>$(window).width())? (this.istopheader? -this._dimensions.subulw+this._dimensions.w : -this._dimensions.w) : menuleft
if ($targetul.queue().length<=1) //if 1 or less queued animations
$targetul.css({left:menuleft+"px", width:this._dimensions.subulw+'px'}).slideDown(jqueryslidemenu.animateduration.over)
},
function(e){
var $targetul=$(this).children("ul:eq(0)")
$targetul.slideUp(jqueryslidemenu.animateduration.out)
}
) //end hover
$curobj.click(function(){
$(this).children("ul:eq(0)").hide()
})
}) //end $headers.each()
$mainmenu.find("ul").css({display:'none', visibility:'visible'})
}) //end document.ready
}
}
//build menu with ID="myslidemenu" on page:
jqueryslidemenu.buildmenu("myslidemenu", arrowimages)
解决方案
推荐阅读
- python-3.x - 如何使用烧瓶将 CSV 数据显示为 html 页面上的表格视图?
- mapbox - Mapbox 瓦片集中的线条未正确渲染
- amazon-web-services - 使用 Glue Connections 连接 Redshift 权限问题
- python - Python中冒号和等号的使用
- python - Python 并发 executor.map() 和 submit()
- javascript - 触发孩子的 onClick 时更改父母状态的更好方法?(反应)
- azure - 关于 Azure 中的异地复制
- javascript - 对象未在 forEach() 方法中推送到数组
- python - Django 模型序列化程序返回 ID
- javascript - 使用 Javascript 添加包含伪元素的类