Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
jQuery-减少鼠标悬停时图像的不透明度_Jquery_Html_Css_Hover_Fadeto - Fatal编程技术网

jQuery-减少鼠标悬停时图像的不透明度

jQuery-减少鼠标悬停时图像的不透明度,jquery,html,css,hover,fadeto,Jquery,Html,Css,Hover,Fadeto,我想实现的是,当你将鼠标悬停在一个图像上时,它的不透明度将减少一半。我一定是犯了一个明显的错误,但我不知道到底是什么。任何小费都将不胜感激 $('.arrow')。悬停( 函数(){ $(this.find('img').fadeTo('slow',0.5); }, 函数(){ $(this.find('img').fadeTo('slow',1); } ); 您需要包括jQuery。另外,删除.find()并将您的类名移动到img元素,或者改用.children() 更新的fiddle:您

我想实现的是,当你将鼠标悬停在一个图像上时,它的不透明度将减少一半。我一定是犯了一个明显的错误,但我不知道到底是什么。任何小费都将不胜感激


$('.arrow')。悬停(
函数(){
$(this.find('img').fadeTo('slow',0.5);
},
函数(){
$(this.find('img').fadeTo('slow',1);
}
);

您需要包括jQuery。另外,删除
.find()
并将您的类名移动到img元素,或者改用
.children()


更新的fiddle:

您需要包括jQuery。另外,删除
.find()
并将您的类名移动到img元素,或者改用
.children()


更新的fiddle:

一个更好的解决方案是使用简单的
CSS
,而无需添加任何javascript,这样您就可以添加一个类并对所有图像进行处理,比如:

.arrow:hover {
  opacity: 0.5;
}

如果你想要缓慢的转换,你可以看看自定义效果。

一个更好的解决方案是使用简单的
CSS
,而不添加任何javascript,这样你就可以添加一个类并对所有图像进行处理,比如:

.arrow:hover {
  opacity: 0.5;
}

如果您想要缓慢的过渡,您可以查看一下以定制效果。

我已经更新了您的JSFIDLE-

您缺少jquery的include。此外,代码中不需要find(“img”)行。使用animate()函数可以轻松完成所需的操作

jQuery

$(".arrow").hover(function(){
   $(this).stop().animate({"opacity": "1"}); 
}, function(){
   $(this).stop().animate({"opacity": "0.5"});
});
CSS:

.arrow{
   opacity: 0.5;
}
HTML:

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<a href="#" id="right-button"><img class="arrow" src="http://placekitten.com/200/200" alt="right" /></a>

我已经更新了您的JSFIDLE-

您缺少jquery的include。此外,代码中不需要find(“img”)行。使用animate()函数可以轻松完成所需的操作

jQuery

$(".arrow").hover(function(){
   $(this).stop().animate({"opacity": "1"}); 
}, function(){
   $(this).stop().animate({"opacity": "0.5"});
});
CSS:

.arrow{
   opacity: 0.5;
}
HTML:

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<a href="#" id="right-button"><img class="arrow" src="http://placekitten.com/200/200" alt="right" /></a>


您需要包括jquery并删除.find(),您也可以通过css不透明性来完成。您需要包括jquery并删除.find(),也可以通过css不透明性来完成。