简体   繁体   English

jQuery淡入淡出图像,但鼠标悬停在图像上

[英]jquery to fade images except for the image with mouse over it

<!DOCTYPE html> 
<html> 
<head> 
    <script>
       $(".playThumb").fadeTo("normal", 1);

        $(".playThumb").hover(function() {
                      $(".playThumb").not($(this)).fadeTo("fast", 0.3); },
      function() {
                      $(".playThumb").not($(this)).fadeTo("fast", 1);
                 });
         </script>

<body> 
<a href="#"><img src="artistry.png" class="playThumb" />
<a href="#"><img src="flavour.png" class="playThumb" />
<a href="#"><img src="quality.png" class="playThumb" />
<a href="#"><img src="Style.png" class="playThumb" />
</body> 
</html>

The images appear but nothing happens, whenever the mouse on the image other images it doesnt fade. 图像出现但什么也没有发生,只要鼠标在图像上其他图像不褪色。

following code works for me 以下代码对我有用

  $(document).ready(function () {

            $(".playThumb").hover(function () {
                $(".playThumb").not($(this)).fadeTo("fast", 0.3);
            }, function () {
                $(".playThumb").not($(this)).fadeTo("fast", 1);
            })
   });

使用.mouseover()事件并尝试

  1. Include jQuery library in the <head> section. <head>部分中包括jQuery库。

  2. Add your JS code in DOM ready function. 在DOM ready函数中添加您的JS代码。

     <script> $(document).ready(function(){ $(".playThumb").fadeTo("normal", 1); $(".playThumb").hover(function() { $(".playThumb").not($(this)).fadeTo("fast", 0.3); }, function() { $(".playThumb").not($(this)).fadeTo("fast", 1); }); }); </script> 
  3. Your HTML does not have ending </head> tag. 您的HTML没有结尾</head>标记。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM