jQuery用css改变颜色:悬停(jQuery changing a color with css :hover)

编程入门 行业动态 更新时间:2024-10-28 14:36:46
jQuery用css改变颜色:悬停(jQuery changing a color with css :hover)

我有以下CSS

#button:hover .inner { background-color: #9c0000; -webkit-animation: circle 1s; -webkit-animation-fill-mode: forwards; -moz-animation: circle 1s; -moz-animation-fill-mode: forwards; animation: circle 1s; animation-fill-mode: forwards; }

这个想法就是那个.inner会在父div里面成长来填补它。 这部分$('#button:hover .inner').css('background-color',colorChoice);但我想允许人们定义background-color ,当我尝试$('#button:hover .inner').css('background-color',colorChoice); 这根本不会改变它。

所以我想知道是否可以使用jQuery从上面的css中更改background-color ,如果我能够提供变量,例如var colorChoice = '#ff0';

我已经提供了我的jsFiddle来向您展示我希望它如何工作

I have the following CSS

#button:hover .inner { background-color: #9c0000; -webkit-animation: circle 1s; -webkit-animation-fill-mode: forwards; -moz-animation: circle 1s; -moz-animation-fill-mode: forwards; animation: circle 1s; animation-fill-mode: forwards; }

The idea is that that .inner will grow inside the parent div to fill it up. This part works but I would like to allow people to define a background-color and when I try $('#button:hover .inner').css('background-color',colorChoice); this doesn't change it at all.

So I was wondering is it actually possible to change the background-color from the css above using jQuery if I was able to supply a variable such as var colorChoice = '#ff0';

I have supplied my jsFiddle to show you how I want it to work

最满意答案

应该可以使用jQuery,但我认为你需要使用http://api.jquery.com/hover/而不是你现在拥有的$('#button:hover .inner')选择器。

$('#button').hover(function(){ $(this).find('.inner').css('background-color',colorChoice); });

更多推荐

本文发布于:2023-08-03 04:26:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1383191.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:颜色   css   jQuery   hover   color

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!