有个jquery左侧导航栏,本来是鼠标移动到上面触发事件。现在想既可以鼠标移动到上面,或者单击也可以触发事件,不知道能不能实现该效果。代码如下:
$(".dropdown > li").hover(function () {
var $container = $(this),
$list = $container.find("ul"),
$anchor = $container.find("a"),
height = $list.height() * 1.1,
multiplier = height / maxHeight; $container.data("origHeight", $container.height());
$container.find("a:first").text(topText);
$("#navigationProcess").empty();
$anchor.addClass("hover"); $list
.show()
.css({
paddingTop: $container.data("origHeight")
}); if (multiplier > 1) {
$container
.css({
width: 153,
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"));
}
;
})
.click(function() {
var $el = $(this);
$el.height($(this).data("origHeight")).find("ul").css({ top: 0 }).hide().end().find("a").removeClass("hover");
});
}
}, function () {
var $el = $(this);
$el
.height($(this).data("origHeight"))
.find("ul")
.css({ top: 0 })
.hide()
.end()
.find("a")
.removeClass("hover");
});
以下是CSDN广告:
$(".dropdown > li").hover(function () {
var $container = $(this),
$list = $container.find("ul"),
$anchor = $container.find("a"),
height = $list.height() * 1.1,
multiplier = height / maxHeight; $container.data("origHeight", $container.height());
$container.find("a:first").text(topText);
$("#navigationProcess").empty();
$anchor.addClass("hover"); $list
.show()
.css({
paddingTop: $container.data("origHeight")
}); if (multiplier > 1) {
$container
.css({
width: 153,
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"));
}
;
})
.click(function() {
var $el = $(this);
$el.height($(this).data("origHeight")).find("ul").css({ top: 0 }).hide().end().find("a").removeClass("hover");
});
}
}, function () {
var $el = $(this);
$el
.height($(this).data("origHeight"))
.find("ul")
.css({ top: 0 })
.hide()
.end()
.find("a")
.removeClass("hover");
});
以下是CSDN广告:
$(".dropdown > li").bind("click", ... );//
$(".dropdown > li").bind("click", function(){
$(this).mouseenter();
});
var m = function(){
//TODO Sth.
}
$(".dropdown > li").unbind("click").bind("click",m).unbind("mouseover").bind("mouseover",m);