我正在创建一个简单的悬停“地图”。基本上悬停在一个标记和一个弹出的细节揭示。无论如何,除了我想添加一个关闭按钮,它大部分工作正常。现在用户可以在弹出框外点击并关闭它,但是我需要在角落添加一个关闭按钮。但是,我的闭幕式不会开火。目前我只是试图在用户点击内容弹出窗口中的任何位置并关闭时设置它。一旦我有这个工作,我将它应用到容器中的一个样式的div。这里是我的HTML的示例:jquery事件不会触发
<div id="container">
<div id="truck"><img src="eVie.png" width="637" height="280" alt="Evie" /></div>
<div class="marker a">
<div class="content a inactive"><img src="solarpanel.jpg" width="240" height="205" alt="Solar Panels" />
<h2>Solar Panels</h2>
<p>Here Comes The Sun: These solar panels capture light and heat from the sun to power exhibits when I’m out visiting around town.</p>
</div>
</div>
<div class="marker b">
<div class="content b inactive"><img src="tailpipe.jpg" width="240" height="205" alt="Tailpipe Area" />
<h2>Tailpipe Area</h2>
<p>No tailpipe, no fumes. That’s how I roll.</p>
</div>
</div>
<div class="marker c">
<div class="content c inactive"><img src="plug.jpg" width="240" height="205" alt="Plug" />
<h2>Plug</h2>
<p>Not An Ordinary Plug: Big trucks need more energy. To get all the energy I need, I have to have a bigger plug and a special outlet!</p>
</div>
</div>
</div>
这里是我的jQuery。除了content.active点击功能之外,它都可以正常工作。为什么?我很难过这个!
$(document).ready(function(){
$(".marker").hover(
function(){
$(this).children(".content.inactive").addClass("show");
$(this).children(".content.inactive").animate({width: 155}, "fast");
}
,
function(){
$(this).children(".content.inactive").animate({width: 5, height: 23}, "fast");
$(this).children(".content.inactive").removeClass("show");
}
);
$(".content.inactive").click(
function(){
$(this).removeClass("inactive");
$(this).addClass("active");
$(this).animate({width: 435, height: 205}, "fast");
$(".inactive").addClass("disabled");
$(".disabled").removeClass("inactive");
$(".disabled").parent().addClass("dim");
$("#truck img").addClass("dim");
}
);
$(".content.active").click(
function(){
$(this).removeClass("active");
$(this).removeClass("show");
$(this).addClass("inactive");
$(this).animate({width: 5, height: 23}, "fast");
$(".disabled").addClass("inactive");
$(".disabled").parent().removeClass("dim");
$(".inactive").removeClass("disabled");
$("#truck img").removeClass("dim");
}
);
$(".content").click(function(){ return false; });
$(document).on("click", function() {
$(".content").animate({width: 5, height: 23}, "fast");
$(".disabled").addClass("inactive");
$(".inactive").removeClass("disabled");
$(".inactive").parent().removeClass("dim");
$("#truck img").removeClass("dim");
$(".active").addClass("inactive");
$(".show").removeClass("show");
$(".active").removeClass("active");
});
});
这里的链接网站:http://stlenergy.org/evie/
任何帮助,将不胜感激。我确定我的逻辑不对,或者我错过了一些显而易见的事情。谢谢!
妮可,我当时不知道,但jQuery有.on()方法,它可以更好地满足您的需求。 – mowwwalker
谢谢,我会考虑将它切换出来。我为最后一个函数使用了.on()方法。我认为这对jQuery(1.7)来说是比较新的。 –