Javascript jquerymouseleave&;滑鼠问题
如何允许用户单击另一个按钮的鼠标指针上显示“单击我”的按钮 这是代码-Javascript jquerymouseleave&;滑鼠问题,javascript,jquery,html,Javascript,Jquery,Html,如何允许用户单击另一个按钮的鼠标指针上显示“单击我”的按钮 这是代码- <div class="hint"> ?</div> <div class="desc"> This is supposed to appear on hover This is supposed to appear on hover This is supposed to appear on hover This is supposed to appea
<div class="hint"> ?</div>
<div class="desc">
This is supposed to appear on hover
This is supposed to appear on hover
This is supposed to appear on hover
This is supposed to appear on hover
<button type="button">
Click me
</button>
</div>
$(document).ready(function() {
var hint = $('.hint');
var desc = $('.desc');
hint.mouseenter(function() {
desc.show();
});
hint.mouseleave(function() {
desc.hide();
});
});
?
这应该出现在悬停状态
这应该出现在悬停状态
这应该出现在悬停状态
这应该出现在悬停状态
点击我
$(文档).ready(函数(){
var hint=$('.hint');
var desc=$('.desc');
hint.mouseenter(函数(){
说明show();
});
hint.mouseleave(函数(){
说明隐藏();
});
});
以下是使
.desc
div成为.hint的子对象的
$(文档).ready(函数(){
var hint=$('.hint');
var desc=$('.desc');
hint.mouseenter(函数(){
说明show();
});
hint.mouseleave(函数(){
说明隐藏();
});
});代码>
.hint{
填充:20px;
背景:白色;
宽度:10px;
高度:10px;
边界半径:50%;
文本对齐:居中;
位置:相对位置;
}
.描述{
显示:无;
宽度:200px;
背景:白色;
z指数:3;
边框:1px实心#CCC;
边界半径:3px;
顶部:20px;
左:-5px;
填充:12px;
颜色:#666;
字体大小:12px;
位置:绝对位置;
最高:50%;
左:50%;
}
?
这应该出现在悬停状态
这应该出现在悬停状态
这应该出现在悬停状态
这应该出现在悬停状态
点击我
使.desc
div成为您的.hint
$(文档).ready(函数(){
var hint=$('.hint');
var desc=$('.desc');
hint.mouseenter(函数(){
说明show();
});
hint.mouseleave(函数(){
说明隐藏();
});
});代码>
.hint{
填充:20px;
背景:白色;
宽度:10px;
高度:10px;
边界半径:50%;
文本对齐:居中;
位置:相对位置;
}
.描述{
显示:无;
宽度:200px;
背景:白色;
z指数:3;
边框:1px实心#CCC;
边界半径:3px;
顶部:20px;
左:-5px;
填充:12px;
颜色:#666;
字体大小:12px;
位置:绝对位置;
最高:50%;
左:50%;
}
?
这应该出现在悬停状态
这应该出现在悬停状态
这应该出现在悬停状态
这应该出现在悬停状态
点击我
只需将.desc
放在.hint
内即可
对于基本工具提示,您需要:
<div title="This is my tooltip">
对于更高级的工具提示,只需将.desc
放在.hint
中即可
对于基本工具提示,您需要:
<div title="This is my tooltip">
对于更高级的工具提示,您有两个选项
1-当工具提示悬停时,可以添加show()
和hide()
:
2-您只能使用css来显示或隐藏它。不确定您是否需要JS来完成类似的简单操作。您有两个选项
1-当工具提示悬停时,可以添加show()
和hide()
:
2-您只能使用css来显示或隐藏它。我不确定你是否需要JS来完成这样简单的事情。这显示了我认为你想要实现的目标。诀窍是当鼠标进入另一个元素时,捕捉触发的事件
$('*').not('.hint').not('.desc').not('.desc>button').mouseenter(function() {
desc.hide();
});
这显示了我认为你想要实现的目标。诀窍是当鼠标进入另一个元素时,捕捉触发的事件
$('*').not('.hint').not('.desc').not('.desc>button').mouseenter(function() {
desc.hide();
});
用另一个div
包装您的html,并将mouseenter
和mouseleave
事件添加到此中
var con=$('.container');
var desc=$('.desc');
con.mouseenter(函数(){
说明show();
});
con.mouseleave(函数(){
说明隐藏();
});代码>
.hint{
填充:20px;
背景:白色;
宽度:10px;
高度:10px;
边界半径:50%;
}
.描述{
显示:无;
宽度:200px;
背景:白色;
z指数:3;
边框:1px实心#CCC;
边界半径:3px;
顶部:20px;
左:-5px;
填充:12px;
颜色:#666;
字体大小:12px;
}
?
这应该出现在悬停上这应该出现在悬停上这应该出现在悬停上这应该出现在悬停上
点击我
用另一个div
包装html,并将mouseenter
和mouseleave
事件添加到此中
var con=$('.container');
var desc=$('.desc');
con.mouseenter(函数(){
说明show();
});
con.mouseleave(函数(){
说明隐藏();
});代码>
.hint{
填充:20px;
背景:白色;
宽度:10px;
高度:10px;
边界半径:50%;
}
.描述{
显示:无;
宽度:200px;
背景:白色;
z指数:3;
边框:1px实心#CCC;
边界半径:3px;
顶部:20px;
左:-5px;
填充:12px;
颜色:#666;
字体大小:12px;
}
?
这应该出现在悬停上这应该出现在悬停上这应该出现在悬停上这应该出现在悬停上
点击我
如果无法更改HTML代码的结构,请尝试稍等片刻,然后使用setTimeout()
隐藏desc
div,这样,如果用户在该div中输入鼠标,则不会通过清除timeout
来隐藏它,请检查下面的示例:
$(document).ready(function() {
var hide_timeout;
var hide_after = 100; //100 ms
var hint = $('.hint');
var desc = $('.desc');
hint.mouseenter(function() {
desc.show();
});
hint.mouseleave(function() {
hide_timeout = setTimeout(function(){
desc.hide();
},hide_after);
});
desc.mouseenter(function() {
clearTimeout(hide_timeout);
});
desc.mouseleave(function() {
desc.hide();
});
});
希望这有帮助
$(文档).ready(函数(){
var隐藏u超时;
var hide_after=100;//100毫秒
var hint=$('.hint');
var desc=$('.desc');
hint.mouseenter(函数(){
说明show();
});
hint.mouseleave(函数(){
hide_timeout=setTimeout(函数(){
说明隐藏();
},躲在后面);
});
desc.mouseenter(函数(){
clearTimeout(隐藏超时);
});
描述mouseleave(函数(){
说明隐藏();