gpt4 book ai didi

javascript - 我怎样才能选择除特定元素以外的所有内容?

转载 作者:行者123 更新时间:2023-11-30 11:34:08 25 4
gpt4 key购买 nike

这是我的代码:

$.fn.right = function() {
return $(document).width() - (this.offset().left + this.outerWidth());
}

$(document).ready(function(){
$('a').bind('mouseenter', function() {
var self = $(this);
this.iid = setTimeout(function() {
var tag_name = self.text(),
top = self.position().top + self.outerHeight(true),
right = self.right();
$('body').append("<div class='tag_info'>Some explanations about "+tag_name+"</div>");

$(".tag_info").css({top: top + "px", right: right + "px"}).fadeIn(200);

}, 525);
}).bind('mouseleave', function(){
if(this.iid){
clearTimeout(this.iid)
$('.tag_info').remove();
}
});
});
    body{
padding: 20px;
direction: rtl;
}

a {
color: #3e6d8e !important;
background-color: #E1ECF4;
padding: 2px 5px;
}
.tag_info{
position: absolute;
width: 130px;
height: 100px;
display:none;
background-color: black;
color: white;
padding: 10px;
}
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<a>long-length-tag</a>
<a>tag</a>

它同样有效,当您的鼠标离开标签时,弹出窗口将被删除。现在,我想在鼠标离开标签并进入该弹出窗口时保留该弹出窗口。否则应将其删除。我该怎么做?

最佳答案

您可以添加条件以在删除弹出窗口之前检查鼠标是否悬停在弹出窗口上:

if ($('.tag_info:hover').length == 0) {....}

并且您需要在弹出窗口本身上添加一个事件以在 mouseleave 上将其删除

查看代码片段:

$.fn.right = function() {
return $(document).width() - (this.offset().left + this.outerWidth());
}

$(document).ready(function() {
$('a').bind('mouseenter', function() {
var self = $(this);
this.iid = setTimeout(function() {
var tag_name = self.text(),
top = self.position().top + self.outerHeight(true),
right = self.right();

var pop_up = $('<div />', {
"class": 'tag_info',
text: "Some explanations about " + tag_name,
mouseleave: function(e){
$(this).remove();
}})

$('body').append(pop_up);

$(".tag_info").css({
top: top + "px",
right: right + "px"
}).fadeIn(200);

}, 525);
}).bind('mouseleave', function() {
if (this.iid) {
clearTimeout(this.iid)
if ($('.tag_info:hover').length == 0) {
$('.tag_info').remove();
}
}
});


});
body {
padding: 20px;
direction: rtl;
}

a {
color: #3e6d8e !important;
background-color: #E1ECF4;
padding: 2px 5px;
}

.tag_info {
position: absolute;
width: 130px;
height: 100px;
display: none;
background-color: black;
color: white;
padding: 10px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<a>long-length-tag</a>
<a>tag</a>

关于javascript - 我怎样才能选择除特定元素以外的所有内容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45126197/

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