悬停效果无法正常使用

如何解决悬停效果无法正常使用

| 自上周以来,我一直对此深思熟虑:(我有一个页面使用选项卡式界面,但菜单是与地图布局相关的图形。我所做的是我使用jQuery代码来实现以下效果五个区域中的每个区域。以下是代码:
      var id1_src = \"/systems_hr/onboarding/Custom%20Pages/Checklist%20EN/images/id1.png\";

      var id11_src = \"/systems_hr/onboarding/Custom%20Pages/Checklist%20EN/images/id1-1.png\";

      var id12_src = \"/systems_hr/onboarding/Custom%20Pages/Checklist%20EN/images/id1-2.png\";

      var id13_src = \"/systems_hr/onboarding/Custom%20Pages/Checklist%20EN/images/id1-3.png\";  

      var id2_src = \"/systems_hr/onboarding/Custom%20Pages/Checklist%20EN/images/id2.png\";

      var id21_src = \"/systems_hr/onboarding/Custom%20Pages/Checklist%20EN/images/id2-1.png\";

      var id22_src = \"/systems_hr/onboarding/Custom%20Pages/Checklist%20EN/images/id2-2.png\";

      var id23_src = \"/systems_hr/onboarding/Custom%20Pages/Checklist%20EN/images/id2-3.png\";    

      var id3_src = \"/systems_hr/onboarding/Custom%20Pages/Checklist%20EN/images/id3.png\";

      var id31_src = \"/systems_hr/onboarding/Custom%20Pages/Checklist%20EN/images/id3-1.png\";

      var id32_src = \"/systems_hr/onboarding/Custom%20Pages/Checklist%20EN/images/id3-2.png\";

      var id33_src = \"/systems_hr/onboarding/Custom%20Pages/Checklist%20EN/images/id3-3.png\";       

      var id4_src = \"/systems_hr/onboarding/Custom%20Pages/Checklist%20EN/images/id4.png\";

      var id41_src = \"/systems_hr/onboarding/Custom%20Pages/Checklist%20EN/images/id4-1.png\";

      var id42_src = \"/systems_hr/onboarding/Custom%20Pages/Checklist%20EN/images/id4-2.png\";

      var id43_src = \"/systems_hr/onboarding/Custom%20Pages/Checklist%20EN/images/id4-3.png\"; 

(...I have a bunch of other similar declarations,58 images in all...)   

      var img = \"\";

      function rolloverArea(area,orgImgSrc,tgtImgSrc,orgCursor,tgtCursor) // jQuery script for rollover effect
      {
        $(\"imgTab\").attr(\"src\",\"\");
        $(\"#imgTab\").attr(\"src\",orgImgSrc);
        $(area).hover(
          function()
            {
              //alert(orgImgSrc + \" on hover\");
              //alert(tgtImgSrc + \" on hover\");
              $(\"imgTab\").attr(\"src\",\"\");
              $(\"#imgTab\").attr(\"src\",tgtImgSrc);
              $(\"#imgTab\").css(\"cursor\",tgtCursor);
            },function()
            {
              //alert(orgImgSrc + \" after hover\");
              //alert(tgtImgSrc + \" after hover\");
              $(\"imgTab\").attr(\"src\",orgImgSrc);
              $(\"#imgTab\").css(\"cursor\",orgCursor);
             }
        );
      }

      function changeImgState(img) // tab interface of Day Week and Month arrows
      {
        var myImgTab = document.getElementById(\"imgTab\");

        switch (img)
        {
          case \'id1\':
        $(myImgTab).attr(\"src\",\"\");      
        $(myImgTab).attr(\"src\",id1_src);
        $(\"#D1\").css({\"visibility\":\"visible\",\"position\":\"relative\",\"top\":\"0px\"});
        $(\"#D2\").css({\"visibility\":\"hidden\",\"top\":\"0px\"});
        $(\"#D3\").css({\"visibility\":\"hidden\",\"top\":\"0px\"});

        // Rollover effect for the image
        rolloverArea(\"#area1\",id1_src,\"auto\",\"auto\");
        rolloverArea(\"#area2\",id11_src,\"pointer\");
        rolloverArea(\"#area3\",id12_src,\"pointer\");
        rolloverArea(\"#area4\",id13_src,\"pointer\");
        rolloverArea(\"#area5\",\"auto\");

        // onClick effect
        $(\"#area2\").click(function() {
          img = \"\";
          changeImgState(\"id2\");

          }
         );

         $(\"#area3\").click(function() {
          img = \"\";
          changeImgState(\"id3\");
          }
         );

         $(\"#area4\").click(function() {
          img = \"\";
          changeImgState(\"id4\");
          }
         );

        break;
          case \'id2\':

        $(myImgTab).attr(\"src\",id2_src);
        $(\"#D1\").css({\"visibility\":\"hidden\",\"top\":\"0px\"});
        $(\"#D2\").css({\"visibility\":\"visible\",\"top\":\"-588px\"});
        $(\"#D3\").css({\"visibility\":\"hidden\",\"top\":\"0px\"});


        // Rollover effect for the image
        rolloverArea(\"#area1\",id2_src,id21_src,\"pointer\");
        rolloverArea(\"#area2\",\"auto\");
        rolloverArea(\"#area3\",id22_src,id23_src,\"auto\");

        // onClick effect
        $(\"#area1\").click(function() {
          $(myImgTab).attr(\"src\",\"\");
          img = \"\";
          changeImgState(\"id1\");
          }
         );

         $(\"#area3\").click(function() {
          img = \"\";
          changeImgState(\"id3\");
          }
         );

         $(\"#area4\").click(function() {
          img = \"\";
          changeImgState(\"id4\");
          }
         );

        break;

          case \'id3\':

        $(myImgTab).attr(\"src\",id3_src);
        $(\"#D1\").css({\"visibility\":\"hidden\",\"top\":\"0px\"});
        $(\"#D3\").css({\"visibility\":\"visible\",\"top\":\"-874px\"});


        // Rollover effect for the image
        rolloverArea(\"#area1\",id3_src,id31_src,id32_src,\"auto\");
        rolloverArea(\"#area4\",id33_src,\"auto\");

        // onClick effect
        $(\"#area1\").click(function() {
          changeImgState(\"id1\");
          }
         );

        $(\"#area2\").click(function() {
          changeImgState(\"id2\");
          }
         );

         $(\"#area4\").click(function() {
          changeImgState(\"id4\");
          }
         );

        break;

          case \'id4\':

        $(myImgTab).attr(\"src\",id4_src);

        // Rollover effect for the image
        rolloverArea(\"#area1\",id4_src,id41_src,id42_src,id43_src,\"auto\");
        rolloverArea(\"#area5\",\"auto\");

        // onClick effect
        $(\"#area1\").click(function() {
          changeImgState(\"id1\");
          }
         );

        $(\"#area2\").click(function() {
          changeImgState(\"id2\");
          }
         );

         $(\"#area3\").click(function() {
          changeImgState(\"id3\");
          }
         );

        break;

(...There are some more similar cases,but they\'re all basically the same as those above,except for the variables...)

        }

      } 

/* My page has two tabs,the first one has three options - First Day,First Week,and First Month. The other one is the one that uses the image. The former is tied to changeTab and the other one uses the changeImgState. However,the former also uses the codes of the latter. */

      function changeTab(tab)
      {   
        switch(tab)     
        {
          case \'day1\':
        var myTab = document.getElementById(\"day1\");

        document.getElementById(\"week1\").className = \"active\";
        document.getElementById(\"month1\").className = \"active\";        
        myTab.className = \"current\"; 

        changeImgState(\"id1\");

        // Rollover effect for the image
        rolloverArea(\"#area1\",\"auto\");

        // onClick effect
        $(\"#area2\").click(function() {
          changeImgState(\"id2\");
          }
         );

         $(\"#area3\").click(function() {
          changeImgState(\"id3\");
          }
         );

         $(\"#area4\").click(function() {
          changeImgState(\"id4\");
          }
         );         

        break; 
          case \'week1\':
        document.getElementById(\"day1\").className = \"active\";
        document.getElementById(\"month1\").className = \"active\";         
        document.getElementById(\"week1\").className = \"current\";

        changeImgState(\"iw1\");

        rolloverArea(\"#area1\",iw1_src,iw11_src,iw12_src,iw13_src,iw14_src,\"pointer\");

        // onClick effect
        $(\"#area2\").click(function() {
          changeImgState(\"iw2\");
          }
         );

         $(\"#area3\").click(function() {
          changeImgState(\"iw3\");
          }
         );

         $(\"#area4\").click(function() {
          changeImgState(\"iw4\");
          }
         );

         $(\"#area5\").click(function() {
          changeImgState(\"iw5\");
          }
         );         

        break;
          case \'month1\':
        document.getElementById(\"week1\").className = \"active\";
        document.getElementById(\"day1\").className = \"active\";         
        document.getElementById(\"month1\").className = \"current\";

        changeImgState(\"im1\");

        // Rollover effect for the image
        rolloverArea(\"#area1\",im1_src,im11_src,im12_src,im13_src,\"auto\");

        // onClick effect
        $(\"#area2\").click(function() {
          changeImgState(\"im2\");
          }
         );

         $(\"#area3\").click(function() {
          changeImgState(\"im3\");
          }
         );

         $(\"#area4\").click(function() {
          changeImgState(\"im4\");
          }
         );         

        break;
        }  

      }

    </script>
    <script lang=\"en\" type=\"text/jscript\">
                  $(window).load(function()
                    {
                      changeTab(\'day1\');
                      //preLoadImages();
                    });
    </script>
该图形分为五个区域,因此我为它们分配了悬停效果。在初始加载时,它可以正常工作。从初始负载(\“ id21 \”)开始,我将鼠标悬停在area1以外的区域上时,情况也是如此。代码按预期工作。当我从其他区域之一单击区域1时出现问题。因此,例如,我在区域2中,然后单击区域1,图像更改开始变得混乱。 例如,在初始加载时,它应该转到id1。该图像显示id1_src(即id1.png)。将鼠标悬停在其他区域会产生以下结果: 区域2:id1-1.png(id11_src) 区域3:id1-2.png(id12_src) 区域4:id1-3.png(id13_src) 当我单击区域2时,图像的源更改为id2.png(id2_src),因此这是我们的基本图形。悬停效果如下: 区域1:id1-1.png(id21_src) 区域3:id1-2.png(id22_src) 区域4:id1-3.png(id23_src) 其他区域遵循相同的模式。当我从任何其他区域单击区域1时,都会遇到错误。以某种方式,而不是遵循上面为id1列出的约定,图形开始变得混乱,因为混合(或保留了)先前的值。悬停效果将显示原始基本图形。 奇怪的是,从其他区域转换时,我仅在id1(或区域1)中遇到此问题。 请帮助:(预先感谢, ch     

解决方法

        如果我对JavaScript有更好的了解,我可以给您一种合理的方式来压缩所有这些行:
var id1_src = \"/systems_hr/onboarding/Custom%20Pages/Checklist%20EN/images/id1.png\";
var id11_src = \"/systems_hr/onboarding/Custom%20Pages/Checklist%20EN/images/id1-1.png\";
有几种方法可以改善此问题;对于带有格式化打印例程的语言,它看起来像这样:
char *basefn = \"/systems_hr/onboarding/Custom%%20Pages/Checklist%%20EN/images/%s.png\";
然后,当您需要一个时,可以使用:
printf(basefn,\"id1\");
printf(basefn,\"id11\");
在没有格式化打印例程的语言中,您可能会使用字符串连接:
basefn = \"/systems_hr/onboarding/Custom%20Pages/Checklist%20EN/images/\"
tailfn = \".png\"

def mk_fn(image)
    return basefn + image + tailfn
end

mk_fn(\"id1\")
mk_fn(\"id11\")
    

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


依赖报错 idea导入项目后依赖报错,解决方案:https://blog.csdn.net/weixin_42420249/article/details/81191861 依赖版本报错:更换其他版本 无法下载依赖可参考:https://blog.csdn.net/weixin_42628809/a
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下 2021-12-03 13:33:33.927 ERROR 7228 [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPL
错误1:gradle项目控制台输出为乱码 # 解决方案:https://blog.csdn.net/weixin_43501566/article/details/112482302 # 在gradle-wrapper.properties 添加以下内容 org.gradle.jvmargs=-Df
错误还原:在查询的过程中,传入的workType为0时,该条件不起作用 &lt;select id=&quot;xxx&quot;&gt; SELECT di.id, di.name, di.work_type, di.updated... &lt;where&gt; &lt;if test=&qu
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct redisServer’没有名为‘server_cpulist’的成员 redisSetCpuAffinity(server.server_cpulist); ^ server.c: 在函数‘hasActiveC
解决方案1 1、改项目中.idea/workspace.xml配置文件,增加dynamic.classpath参数 2、搜索PropertiesComponent,添加如下 &lt;property name=&quot;dynamic.classpath&quot; value=&quot;tru
删除根组件app.vue中的默认代码后报错:Module Error (from ./node_modules/eslint-loader/index.js): 解决方案:关闭ESlint代码检测,在项目根目录创建vue.config.js,在文件中添加 module.exports = { lin
查看spark默认的python版本 [root@master day27]# pyspark /home/software/spark-2.3.4-bin-hadoop2.7/conf/spark-env.sh: line 2: /usr/local/hadoop/bin/hadoop: No s
使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams[&#39;font.sans-serif&#39;] = [&#39;SimHei&#39;] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -&gt; systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping(&quot;/hires&quot;) public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate&lt;String
使用vite构建项目报错 C:\Users\ychen\work&gt;npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-