• <legend id='cTVAC'><style id='cTVAC'><dir id='cTVAC'><q id='cTVAC'></q></dir></style></legend>

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

        <bdo id='cTVAC'></bdo><ul id='cTVAC'></ul>

        <tfoot id='cTVAC'></tfoot>
      1. jQuery:悬停链接时在div中动画(淡化)背景颜色或图像?

        jQuery: Animate (fade) background-color or image in div when hover a link?(jQuery:悬停链接时在div中动画(淡化)背景颜色或图像?)
            <tbody id='LxIWj'></tbody>
            <bdo id='LxIWj'></bdo><ul id='LxIWj'></ul>

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

              <tfoot id='LxIWj'></tfoot>
                • <legend id='LxIWj'><style id='LxIWj'><dir id='LxIWj'><q id='LxIWj'></q></dir></style></legend>

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

                  本文介绍了jQuery:悬停链接时在div中动画(淡化)背景颜色或图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我想在 redhotchilipeppers.com 上创建一个菜单.当您将链接悬停在右上角时,整个页面的背景颜色会发生变化.原始图像仍然在后面,只是颜色发生了变化.

                  I want to create a menu such as on redhotchilipeppers.com. When you hover a link in the top right the background color of the whole page change. The original image is still in the back, it's just the color that changes.

                  您可以在下面看到我是如何尝试实现它的.它的褪色太慢了,当我悬停一个链接然后另一个链接时,它首先褪色到第一个链接 bg 颜色,然后恢复正常,然后到第二个链接 bg 颜色.在 redhotchilipeppers.com 上,bg 颜色会立即消失.

                  Below you can see how I tried to accomplish it. It's fades way too slow and when I hover one link and then another it first fades to the first links bg color and then back to normal and then to the second links bg color. On redhotchilipeppers.com the bg colors fades right away.

                  这是我现在使用的代码:

                  Here's the code I use right now:

                  <head>
                  <style>
                  body {
                  margin:0 auto;
                  top:0;
                  left:0;
                  height:100%;
                  width:100%;
                  background:url(images/bg.jpg);
                  }
                  
                  #container {
                  width:100%;
                  height:100%;
                  display:block;
                  position:absolute;
                  top:0;
                  left:0;
                  opacity:0.4;
                  filter:alpha(opacity=40);
                  -moz-opacity: 0.4;
                  background-color:#fff;
                  z-index:-1;
                  }
                  
                  .link {
                  position:inherit;
                  z-index:1;
                  float:right;
                  padding-top:100px;
                  }
                  </style>
                  </head>
                  
                  <body>
                  <div id="container"></div>
                  <div class="link">
                  <a href="" id="linktomouseover"><img src="images/menu_start.png" alt="" /></a><a href="" id="linktomouseover2"><img src="images/menu_contactus.png" alt="" /></a>
                  </div>
                  
                  <script> 
                  jQuery('#linktomouseover').hover(function() { 
                  jQuery('#container').animate({ backgroundColor: "#2154b9"}, 500);
                  }).mouseleave(function(){
                  jQuery('#container').animate({ backgroundColor: "#ffffff"}, 500); 
                  });
                  
                  jQuery('#linktomouseover2').hover(function() { 
                  jQuery('#container').animate({ backgroundColor: "#ac1c27"}, 500);
                  }).mouseleave(function(){
                  jQuery('#container').animate({ backgroundColor: "#ffffff"}, 500); 
                  });
                  </script>
                  </body>
                  

                  我做错了什么?还是有更好的方法来解决这个问题?

                  What am I doing wrong? Or is it a better way to solve this?

                  推荐答案

                  令人惊讶的是,jQuery 不会为背景颜色设置动画(没有插件).最简单的方法是使用 CSS 更改类并使用 CSS 过渡,如下所示:

                  Surprisingly, jQuery won't animate background colors (without a plugin). The easiest way is to change classes with CSS and use CSS transitions instead, like so:

                  $('#linktomouseover').hover(function() {
                      $('#container').addClass('hover1')
                  }, function() {
                      $('#container').removeClass('hover1')
                  });
                  
                  #container {
                      transition: background-color 0.5s;
                      -moz-transition: background-color 0.5s;
                      -webkit-transition: background-color 0.5s;
                      -o-transition: background-color 0.5s;
                  }
                  

                  jsFiddle:http://jsfiddle.net/kkzLW/

                  无论如何它更符合语义:)

                  It's more semantic anyway :)

                  这篇关于jQuery:悬停链接时在div中动画(淡化)背景颜色或图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  append() 方法在被选元素的结尾(仍然在内部)插入指定内容。 语法: $(selector).append( content ) var creatPrintList = function(data){ var innerHtml = ""; for(var i =0;i data.length;i++){ innerHtml +="li class='contentLi'"; innerHtml +="a href
                  quot;Each child in an array should have a unique key propquot; only on first time render of page(“数组中的每个孩子都应该有一个唯一的 key prop仅在第一次呈现页面时)
                  How do I make a TextGeometry multiline? How do I put it inside a square so it wraps like html text does inside a div?(如何制作 TextGeometry 多线?如何将它放在一个正方形内,以便它像 html 文本一样包裹在 div 内?) - IT屋-程序员软件开发技术分享社
                  ExecJS::ProgramError: SyntaxError: Reserved word quot;functionquot;(ExecJS::ProgramError: SyntaxError: 保留字“function)
                  Infinite scroll and will_paginate appending the #39;next page#39; of items multiple times(无限滚动和 will_paginate 多次附加项目的“下一页)
                  What is cleanest way to turn Array of JQuery Promises into a JQuery Promise of an Array?(将 JQuery Promise 数组转换为数组的 JQuery Promise 的最简洁方法是什么?)
                  • <legend id='4zKzM'><style id='4zKzM'><dir id='4zKzM'><q id='4zKzM'></q></dir></style></legend>

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

                            <small id='4zKzM'></small><noframes id='4zKzM'>