从 jQuery 动画 Div 中排除文本
我正在使用 joomla 构建一个网站,最近添加了一个 jQuery 模块,当您将鼠标悬停在包含的 div 上时,该模块会更改其不透明度。它包含文本,并且文本看起来有点俗气,因为它也失去了不透明度。所以我想知道如何定位 div,但排除文本,以便文本保持 100% 不透明度。
这是我的代码:
<script src="http://code.jquery.com/jquery-1.4.4.js"></script>
<script>jQuery.noConflict();
jQuery(document).ready(function() {
//settings
var opacity = 0.5, toOpacity = 1, duration = 350;
//set opacity ASAP and events
jQuery('.opacity').css('opacity',opacity).hover(function() {
jQuery(this).fadeTo(duration,toOpacity);
}, function() {
jQuery(this).fadeTo(duration,opacity);
}
);
});
</script>
I am building a site using joomla, and I recently added a jQuery module that changes the opacity of the containing div when you hover over it. It contains text, and the text kinda looks cheesy because it loses opacity as well. So I was wondering, how I could target the div, but exclude the text so, that the text remains at 100% opacity.
Here is my code:
<script src="http://code.jquery.com/jquery-1.4.4.js"></script>
<script>jQuery.noConflict();
jQuery(document).ready(function() {
//settings
var opacity = 0.5, toOpacity = 1, duration = 350;
//set opacity ASAP and events
jQuery('.opacity').css('opacity',opacity).hover(function() {
jQuery(this).fadeTo(duration,toOpacity);
}, function() {
jQuery(this).fadeTo(duration,opacity);
}
);
});
</script>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我尝试使用 CSS 来更改容器的不透明度,同时保持完全不透明的子级,但不幸的是,我得出的结论是这是不可能的。
我建议你做的是将两个 div 放置在同一位置,但仅对用作背景层的一个 div 的不透明度进行动画处理。
I've tried to use CSS to change the opacity of a container while maintaining totally opaque children and came to the conclusion that it can't be done, unfortunately.
What I suggest you do is have two divs positioned in the same location but only animate the opacity of one which works as a background layer.