除非单击第二个按钮,否则仅保持悬停背景图像处于活动状态(Keep hover background image active only unless second button is clicked)

编程入门 行业动态 更新时间:2024-10-26 17:27:52
除非单击第二个按钮,否则仅保持悬停背景图像处于活动状态(Keep hover background image active only unless second button is clicked)

我有两个按钮(每个按钮都带有灰色背景图像),每个按钮都有一个颜色悬停背景图像。 除非单击旁边的按钮,否则我只想保持颜色背景处于活动状态。 现在,如果您点击屏幕上的任何位置,该背景悬停图像的焦点将恢复为原始的灰色按钮/图像。

这是CSS的小提琴: http : //jsfiddle.net/J6DP9/8/

<div class="buttons-holder"> <button id="rdb1" type="button" name="toggler" value="US">United States</button> <button id="rdb2" type="button" name="toggler" value="International">International</button> </div> </div> </div> <div class="cms-pages"> <div class="divclearboth"></div> <hr> </div> <div id="blk-0" class="toHide"> <div class="center-form-img"> <img src="{{media url=" wysiwyg/form-inactive.jpg "}}" alt="" /> </div> </div> <div id="blk-US" class="toHide" style="display:none;">{{block type=core/template name=wholesale-us template=cmg/wholesale-us.phtml}}</div> <div id="blk-International" class="toHide" style="display:none;">{{block type=core/template name=wholesale-intl template=cmg/wholesale-intl.phtml}}</div>

这是JS:

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> <script> $(function () { $("[name=toggler]").click(function () { $('.toHide').hide(); $("#blk-" + $(this).val()).fadeIn(); }); }); </script>

任何帮助深表感谢! 提前致谢。

I have two buttons (each with grey background image), and for each of those a color hover background image. I'd like to keep the color background active only unless the button next to it is clicked. Right now if you click anywhere on the screen the focus of that background hover image reverts back to the original grey button/image.

Here's the fiddle with the CSS: http://jsfiddle.net/J6DP9/8/

<div class="buttons-holder"> <button id="rdb1" type="button" name="toggler" value="US">United States</button> <button id="rdb2" type="button" name="toggler" value="International">International</button> </div> </div> </div> <div class="cms-pages"> <div class="divclearboth"></div> <hr> </div> <div id="blk-0" class="toHide"> <div class="center-form-img"> <img src="{{media url=" wysiwyg/form-inactive.jpg "}}" alt="" /> </div> </div> <div id="blk-US" class="toHide" style="display:none;">{{block type=core/template name=wholesale-us template=cmg/wholesale-us.phtml}}</div> <div id="blk-International" class="toHide" style="display:none;">{{block type=core/template name=wholesale-intl template=cmg/wholesale-intl.phtml}}</div>

Here's the JS:

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> <script> $(function () { $("[name=toggler]").click(function () { $('.toHide').hide(); $("#blk-" + $(this).val()).fadeIn(); }); }); </script>

Any help is much appreciated! Thanks in advance.

最满意答案

我更新了您的代码,将active类添加到最后一次单击的button并从所有其他类中删除active类。

http://jsfiddle.net/J6DP9/16/

I updated your code to add an active class to the last clicked button and remove the active class from all others.

http://jsfiddle.net/J6DP9/16/

更多推荐

div>,button,<div,电脑培训,计算机培训,IT培训"/> <meta name="descri

本文发布于:2023-08-04 15:04:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1417509.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:第二个   单击   按钮   图像   状态

发布评论

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

>www.elefans.com

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