jquery - CSS 图像滚动贴图和 jQuery : how to use a second li list?

标签 jquery css rollover imagemap

我目前正在使用这个可点击的 map ( Wolf's map ),但除了用作脚本基础的国家列表之外,我还想使用第二个 li 国家列表。出于展示原因,第二个菜单不能与 map 位于同一 DIV 中。我一直在搜索 JQuery 文档,以了解如何在所选元素之外的另一个元素上触发操作,但我不确定我是否做对了 - 可能不是因为它不起作用。

原始脚本如下所示:

    $(document).ready(function(){

 var new_map='<span class="map"><span class="s1" /><span class="s2" /><span class="s3" /><span class="s4" /><span class="s5" /><span class="s6" /><span class="s7" /><span class="s8" /><span class="s9" /><span class="s10" /><span class="s11" /><span class="s12" /><span class="s13" /><span class="s14" /><span class="s15" /><span class="s16" /><span class="s17" /><span class="s18" /></span>';
 var new_bg=$("<span>");
 new_bg.addClass("bg");
 $("#europe li a").append(new_map);
 $("#europe li a").append(new_bg);

});

我想做的是在悬停另一个不是#europe li a 的元素时触发相同的操作。我试过这个:

$(document).ready(function(){

 var new_map='<span class="map"><span class="s1" /><span class="s2" /><span class="s3" /><span class="s4" /><span class="s5" /><span class="s6" /><span class="s7" /><span class="s8" /><span class="s9" /><span class="s10" /><span class="s11" /><span class="s12" /><span class="s13" /><span class="s14" /><span class="s15" /><span class="s16" /><span class="s17" /><span class="s18" /></span>';
 var new_bg=$("<span>");
 new_bg.addClass("bg");
 $("#carteeurope li a").append(new_map);
 $("#carteeurope li a").append(new_bg);

 $("#menudroite li a").hover(function(){
 $(new_map).appendTo("#carteeurope li a");
 $(new_bg).appendTo("#carteeurope li a");
 });

});

它做了一些事情,但没有达到预期的效果:看起来 map 确实可以移动,但不能移动到好的位置(一些国家在第二个菜单上悬停几次后会变成白色背景)。

如果你能帮助我,我将不胜感激!

问候。

PS:一些相关的 HTML 和 CSS 部分。

原始列表

<div id="b">
     <ul id="europe" class="bottom five_columns">
      <li id="europe1"><a href="#" title="Albania">Albania</a></li>
      <li id="europe2"><a href="#" title="Andorra">Andorra</a></li>
      <li id="europe3"><a href="#" title="Austria">Austria</a></li>
      ...

我要添加的菜单

<div id="menudroite">
<ul>
<li><a href="#">Accueil</a></li>
<li><a href="#" title="France">France</a></li>
<li><a href="#" title="Grèce">Grèce</a></li>
...

原始 CSS

#europe,#europe span.bg{background:transparent url('europe-600px.png') no-repeat -9999px 0}
#europe{position:relative;top:0;left:0;display:block;background-position:0 -966px;list-style:none}
 #europe *{padding:0;margin:0;border:0 none;outline:0 none}
  #europe li{cursor:pointer}
  #europe li span{position:absolute;display:block;width:0;height:0;z-index:15}
  #europe li a span.bg{z-index:3}
  #europe li .map{top:0;left:0}
...
 #europe li span{position:absolute;display:block;top:0;left:0;width:0;height:0;z-index:15}
 #europe1 a:hover .bg{top:395px;left:303px;width:20px;height:40px;background-position:-10px -10px} #europe1 .s1{top:401px;left:303px;width:15px;height:32px} #europe1 .s2{top:397px;left:305px;width:8px;height:4px} #europe1 .s3{top:418px;left:318px;width:4px;height:9px}
 #europe2 a:hover .bg{top:385px;left:133px;width:5px;height:6px;background-position:-35px -10px} #europe2 .s1{top:383px;left:131px;width:9px;height:10px}
...

最佳答案

这个函数解决的问题:

  $("#menudroite li.menudroitepays a").hover(
   function(){
    var country=$(this).attr("id");
    $("#europe" + country + " a").addClass("active");
   },
   function(){
    var country=$(this).attr("id");
    $("#europe" + country + " a").removeClass("active");
   }

关于jquery - CSS 图像滚动贴图和 jQuery : how to use a second li list?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3382417/

相关文章:

javascript - 如何使用迭代插入 HTML

jquery - jQuery : text() and html() ? 有什么区别

jQuery 翻转未预加载

css - 在画廊图像缩略图 CSS 上悬停时显示标题

javascript - jquery 预加载带有翻转的图像

javascript - jquery中如何根据div的hover获取类名

JQuery 移动页面 div 边距在转换期间发生变化。我该如何预防?

html - 垂直对齐到父级的中间

html - NavBar Logo 未出现在 Foundation 6 dist 上

css - 如何在 Razor View 上引用 .css 文件?