使用 jQuery 淡入?
我正在尝试编写一个函数,以便当您将鼠标悬停在热点上时,X div 的内容会根据您所在的热点而变化。
我一直在阅读 jQuery 的 fadeIn 函数,只是不确定如何实现它?
我尝试了下面的方法,但没有成功...
$(".texas").hover(
function () {
$(".description").fadeIn('slow').html("Texas");
}
);
下面是我的原始代码...
$(document).ready(function() {
$(".uk").hover(
function () {
$(".description").html("Test Blah");
}
);
$(".singapore").hover(
function () {
$(".description").html("singapore");
}
);
$(".texas").hover(
function () {
$(".description").html("Texas");
}
);
});
<div class="wrap">
<div class="description">
<span class="country">Singapore</span>
<p>Temporibus autem quibusdam et aut officiis.</p><p>Debitis aut rerum necessitatibus saepe eveniet ut et voluptates repudiandae sint et molestiae non recusandae. </p>
</div>
<div class="map">
<a href="#" class="circle uk">Manchester</a>
<a href="#" class="circle singapore">Singapore</a>
<a href="#" class="circle texas">Texas</a>
</div>
</div>
Im trying to write a function so that when you hover over a hotspot the content of X div changes depending on what hotspot you're on.
I've been reading up on jQuery's fadeIn function only im unsure how I'd go about implementing it?
I've tried the below with no luck...
$(".texas").hover(
function () {
$(".description").fadeIn('slow').html("Texas");
}
);
And below is my original code...
$(document).ready(function() {
$(".uk").hover(
function () {
$(".description").html("Test Blah");
}
);
$(".singapore").hover(
function () {
$(".description").html("singapore");
}
);
$(".texas").hover(
function () {
$(".description").html("Texas");
}
);
});
<div class="wrap">
<div class="description">
<span class="country">Singapore</span>
<p>Temporibus autem quibusdam et aut officiis.</p><p>Debitis aut rerum necessitatibus saepe eveniet ut et voluptates repudiandae sint et molestiae non recusandae. </p>
</div>
<div class="map">
<a href="#" class="circle uk">Manchester</a>
<a href="#" class="circle singapore">Singapore</a>
<a href="#" class="circle texas">Texas</a>
</div>
</div>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我不确定您的 HTML 到底是什么样子,但我相信以下内容应该适合您:
您可以在此处查看小提琴:
http://jsfiddle.net/gcArd/
更新:
根据您提供的 HTML,此更新版本应该适合您:
http://jsfiddle.net/gcArd/2/
I'm not sure exactly what your HTML look like but I believe the below should work for you:
You can view the fiddle here:
http://jsfiddle.net/gcArd/
UPDATE:
Based on the HTML you posed this updated version should work for you:
http://jsfiddle.net/gcArd/2/
我认为这会让你最接近你想要实现的目标。
http://jsfiddle.net/fXTbf/
您不希望鼠标悬停时出现淡入淡出效果已经显示的元素。接下来,您可以绑定到圆圈类,而不是单个位置类。
I think this gets you the closest to what you are trying to achieve.
http://jsfiddle.net/fXTbf/
You don't want the fade effect to occur when you mouse over an already shown element. Next, you can bind to circle class as opposed to individual location classes.
您需要一个 div 或某个容器来存放 .description 的每个可能的内容。这样,你就可以这样做:
You need a div or some container for each of the possible contents of .description. In that way, you could do this:
这是基于 Abe Miesser 的回答。我认为从视觉上来说,它实际上没有那么迟钝。
http://jsfiddle.net/y6Dp4/
This is based on Abe Miesser's answer. I thinks it's actually a lot less sluggy, visually speaking.
http://jsfiddle.net/y6Dp4/