效果如下:
测试代码,鼠标以上去试试:
(function () {
$(".dropdown-toggle,.dropdown-menu").hover(function () {
if ($(this).attr("aria-expanded") != "true" && $(this).hasClass("dropdown-toggle")) {
$(this).click();
}
}, function () {
if ($(this).attr("aria-expanded") == "true" || $(this).parent().hasClass("open")) {
if ($(this).parent().find("ul:hover").length == 0) {
$(this).click()
}
}
});
})();
源码如下,仅供参考,谢谢:
$("pre").mouseover(function (e) {
var _that = $(this);
_that.css("position", "relative");
_that.addClass("activePre");
var copyBtn = _that.find('.copyBtn');
if (!copyBtn || copyBtn.length <= 0) {
var copyBtn = '复制';
_that.append(copyBtn);
}
}).mouseout(function (e) {
var _that = $(this);
var copyBtn = _that.find('.copyBtn');
var copyBtnHover = _that.find('.copyBtn:hover');
if (copyBtnHover.length == 0) {
copyBtn.remove();
_that.removeClass("activePre");
}
});
function copyCode() {
var activePre = $(".activePre");
if (!activePre || activePre.length <= 0) {
return;
}
activePre = activePre[0];
var clone = $(activePre).clone();
clone.find('.copyBtn').remove();
var clipboard = new ClipboardJS('.copyBtn', {
text: function () {
return clone.text();
}
});
clipboard.on("success", function (e) {
$(".copyBtn").html("复制成功");
clipboard.destroy();
clone.remove();
});
clipboard.on("error", function (e) {
clipboard.destroy();
clone.remove();
});
}