【问题标题】:jQuery on hover image change opacity/fadeout and text fade in悬停图像上的jQuery改变不透明度/淡出和文本淡入
【发布时间】:2013-07-31 18:50:23
【问题描述】:

对于 jQuery,我是一个完全的新手,我知道这个网站上有很多与我类似的问题,但我找不到与我想要的足够接近的问题。

我想要的是当鼠标悬停在图像上时,图像的不透明度会降低(或完全淡出),并且文本会淡入该图像所在的顶部。我还希望该文本成为同一页面上某个位置的链接(但我确信我可以做到这一点)。

如果有人可以为我在 jsfiddle 中组合一些东西,我将非常感激,因为我还没有足够的能力将 jQuery 现有示例修改为我需要的。

谢谢!

【问题讨论】:

  • 向我们展示您已经完成的工作。
  • 你不能只使用所有“新”和“热”的 CSS 吗?与 :hover、:active 或 CSS3 伪类类似,例如 :before 和 :after?还是浏览器支持对您很重要?实际上 CSS :hover with opacity 被广泛支持(除了 IE,这里使用过滤器)。
  • @MarkusHofmann "..is widely supported ( except IE" 这就是为什么我们不能使用任何“新”或“热”的东西:(
  • 你可以使用带有 js 后备的 css 吗?实际上,如果您在 css 中使用 -ms-filter,则不透明度在旧 IE(IE

标签: jquery hover opacity fadein fadeout


【解决方案1】:

试试这个,也许对你有帮助:

HTML:

<img class="image" src="" alt="TestImage"></img><a id="link">This is the link content</a>

CSS:

 #link {
    display: none;
 }

脚本:

$(".image").hover(function(e) {
      e.preventDefault();
      $(this).fadeOut('slow', function(e) {
          $('#link').fadeIn('slow');
      });
});

 $("#link").mouseout(function(e) {
      e.preventDefault();
      $(this).fadeOut('slow', function(e) {
          $(".image").fadeIn('slow');
      });
});

$( document ).ready(function() {
    $(".image")[0].hover(); 
});

Fiddle

更新脚本:

$(".image").hover(function(e) {
      e.preventDefault();
      $(this).stop().fadeOut('slow', function(e) {
          $('#link').stop().fadeIn('slow');
      });
});

$("#link, .image").mouseout(function(e) {
      e.preventDefault();
      if($(this).is("img"))
      {
          $(".image").stop().fadeOut('slow', function(e) {
              $('#link').stop().fadeOut('slow', function(e) {
                  $(".image").stop().fadeIn('slow');
              });
          });
      }
      else
      {
          $('#link').stop().fadeOut('slow', function(e) {
              $(".image").stop().fadeIn('slow');
          });
      }
});

$( document ).ready(function() {
    $(".image")[0].hover(); 
});

Updated Fiddle

【讨论】:

  • 这正是我想要的。非常感谢。我忘了提到的另一件事是,当鼠标移开/远离图像时,文本会淡出,图像会再次淡入。脚本是什么?
  • 更新帖子,请查收
  • 谢谢阿布舍克。使用您的脚本,您需要将鼠标移到文本上,然后在文本淡出和图像淡入之前将其移开。是否有可能当鼠标移出淡出的图像区域时,然后文本淡出,图像淡入。这在 jsfiddle 中也很有效,但我无法让它在 Dreamweaver 或 Rapidweaver 中工作。知道为什么吗?
  • 希望您添加了 jQuery 参考。
  • 是的,我是。我将如何在上面的帖子中执行脚本重新淡出文本和淡入图像,而无需先将鼠标悬停在文本上?
猜你喜欢
  • 1970-01-01
  • 2023-03-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-01-23
  • 1970-01-01
  • 2019-08-27
相关资源
最近更新 更多