• <legend id='7X2ux'><style id='7X2ux'><dir id='7X2ux'><q id='7X2ux'></q></dir></style></legend>
      1. <i id='7X2ux'><tr id='7X2ux'><dt id='7X2ux'><q id='7X2ux'><span id='7X2ux'><b id='7X2ux'><form id='7X2ux'><ins id='7X2ux'></ins><ul id='7X2ux'></ul><sub id='7X2ux'></sub></form><legend id='7X2ux'></legend><bdo id='7X2ux'><pre id='7X2ux'><center id='7X2ux'></center></pre></bdo></b><th id='7X2ux'></th></span></q></dt></tr></i><div id='7X2ux'><tfoot id='7X2ux'></tfoot><dl id='7X2ux'><fieldset id='7X2ux'></fieldset></dl></div>
          <bdo id='7X2ux'></bdo><ul id='7X2ux'></ul>

        <small id='7X2ux'></small><noframes id='7X2ux'>

      2. <tfoot id='7X2ux'></tfoot>

        将鼠标悬停在图像上以显示按钮,并且在悬停在实际按钮上时不触发

        Hover over image to show buttons and don#39;t trigger when hovering over actual buttons(将鼠标悬停在图像上以显示按钮,并且在悬停在实际按钮上时不触发)

        • <tfoot id='3C0FQ'></tfoot>
          <legend id='3C0FQ'><style id='3C0FQ'><dir id='3C0FQ'><q id='3C0FQ'></q></dir></style></legend>
          <i id='3C0FQ'><tr id='3C0FQ'><dt id='3C0FQ'><q id='3C0FQ'><span id='3C0FQ'><b id='3C0FQ'><form id='3C0FQ'><ins id='3C0FQ'></ins><ul id='3C0FQ'></ul><sub id='3C0FQ'></sub></form><legend id='3C0FQ'></legend><bdo id='3C0FQ'><pre id='3C0FQ'><center id='3C0FQ'></center></pre></bdo></b><th id='3C0FQ'></th></span></q></dt></tr></i><div id='3C0FQ'><tfoot id='3C0FQ'></tfoot><dl id='3C0FQ'><fieldset id='3C0FQ'></fieldset></dl></div>
          1. <small id='3C0FQ'></small><noframes id='3C0FQ'>

                  <bdo id='3C0FQ'></bdo><ul id='3C0FQ'></ul>
                    <tbody id='3C0FQ'></tbody>
                • 本文介绍了将鼠标悬停在图像上以显示按钮,并且在悬停在实际按钮上时不触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我试图让按钮在悬停在图像上时出现.以下作品:

                  I'm trying to get buttons to appear when hovering over an image. The following works:

                  
                      jQuery('.show-image').mouseenter(function() {
                   jQuery('.the-buttons').animate({
                    opacity: 1
                   }, 1500);
                  }).mouseout(function() {
                   jQuery('.the-buttons').animate({
                    opacity: 0
                   }, 1500); 
                  });
                  

                  但是,当从图像移动到按钮(在图像上方)时,会触发 mouseout/mouseenter,因此按钮会淡出然后淡入(按钮与图像具有相同的类,否则它们只是保持淡出).我怎样才能防止这种情况触发?我还使用 jQuery 的悬停尝试了上面的代码;相同的结果.这是显示不透明度为 1 的按钮的图像的详细信息(因为我在图像上方):

                  However, when moving from the image to the button (which is over the image), the mouseout/mouseenter is triggered, so the buttons fade out then fade back in (the buttons have the same class as the image, otherwise they just stay faded out). How can I prevent this from triggering? I've also tried the above code using jQuery's hover; same results. Here's a detail of the image showing the button with opacity 1 (because I'm over the image):

                  http://i.stack.imgur.com/egeVq.png

                  提前感谢您的任何建议.

                  Thanks in advance for any suggestions.

                  推荐答案

                  最简单的解决方案是将两者放在同一个父div中,并给父divshow-image 类.

                  The simplest solution is to put the two in the same parent div and give the parent div the show-image class.

                  我喜欢使用.hover() 以节省一些击键.(所有悬停都是实现 .mouseenter().mouseleave(),但您不必输入它们)

                  I like to use .hover() to save a few key strokes. (alll hover does is implement .mouseenter() and .mouseleave(), but you don't have to type them out)

                  此外,淡出 $(this).find(".the-buttons") 非常重要,这样您就只能更改悬停在 div 上的按钮,否则您将更改整个页面上的所有 .the-buttons.find() 只是寻找后代.

                  Additionally it's very imporant to fade $(this).find(".the-buttons") so that you only change the button in the hovered over div otherwise you would change all of the .the-buttons on the entire page! .find() just looks for descendants.

                  最后,.animate() 可以,但为什么不直接使用 .fadeIn().fadeOut()?

                  Finally, .animate() will work, but why not just use .fadeIn() and .fadeOut()?

                  JS:

                  jQuery(function() {                                              // <== Doc ready
                  
                      jQuery(".the-buttons").hide();                  // Initially hide all buttons
                  
                      jQuery('.show-image').hover(function() {
                           jQuery(this).find('.the-buttons').fadeIn(1500);         // use .find() !
                      }, function() {
                          jQuery(this).find('.the-buttons').fadeOut(1500);         // use .find() !
                      });
                  });
                  

                  试试这个 jsFiddle

                  HTML: - 像这样的

                  Try it out with this jsFiddle

                  HTML: - Something like this

                  <div class="show-image">
                      <img src="http://i.stack.imgur.com/egeVq.png" />
                      <input class="the-buttons" type="button" value=" Click " />
                  </div>
                  

                  CSS: - 像这样的东西.您的可能会有所不同.

                  CSS: - Something like this. Yours will likely be different.

                  div {
                      position: relative;
                      float:left;
                      margin:5px;}
                  div input {
                      position:absolute;
                      top:0;
                      left:0; }
                  

                  这篇关于将鼠标悬停在图像上以显示按钮,并且在悬停在实际按钮上时不触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Move link image 5px up on hover(悬停时将链接图像向上移动 5px)
                  How do I inspect CSS pseudo classes with firebug?(如何使用 firebug 检查 CSS 伪类?)
                  Why doesn#39;t CSS hover work on table rows when the cells inside the rows have class names?(当行内的单元格具有类名时,为什么 CSS 悬停在表格行上不起作用?)
                  Hover image - display div over it(悬停图像 - 在其上显示 div)
                  How to apply a CSS class on hover to dynamically generated submit buttons?(如何在悬停时将 CSS 类应用于动态生成的提交按钮?)
                  Differences between CSS3 :hover and :focus?(CSS3 :hover 和 :focus 的区别?)
                  <tfoot id='wFoxy'></tfoot>

                      <i id='wFoxy'><tr id='wFoxy'><dt id='wFoxy'><q id='wFoxy'><span id='wFoxy'><b id='wFoxy'><form id='wFoxy'><ins id='wFoxy'></ins><ul id='wFoxy'></ul><sub id='wFoxy'></sub></form><legend id='wFoxy'></legend><bdo id='wFoxy'><pre id='wFoxy'><center id='wFoxy'></center></pre></bdo></b><th id='wFoxy'></th></span></q></dt></tr></i><div id='wFoxy'><tfoot id='wFoxy'></tfoot><dl id='wFoxy'><fieldset id='wFoxy'></fieldset></dl></div>

                        <tbody id='wFoxy'></tbody>
                        <legend id='wFoxy'><style id='wFoxy'><dir id='wFoxy'><q id='wFoxy'></q></dir></style></legend>
                        • <bdo id='wFoxy'></bdo><ul id='wFoxy'></ul>

                            <small id='wFoxy'></small><noframes id='wFoxy'>