Darling_lxy 2022-04-27 23:55 采纳率: 71.4%
浏览 84
已结题

jquery怎么控制opacity的属性

.item {
                position: absolute;
                opacity: 0;
            }
            .hotSpot{
                position: absolute;
            }
<div class="hotSpot" id="beijin"  style="background: #ff007f; left:2184px;top: 1015px;width: 50px;height: 80px;border-radius:10px;transform:rotate(40deg)"></div> 
<img id="beijin" class="item" src="image/beijin.png" style="left: 2170px; top: 1005px;">
function showDiv() {
            $('#beijin').click(function(){
                if($(this).css('opacity') ==0 ){
                    $(this).css('opacity', '0')
                }else{
                    $(this).css('opacity','1');
                }
            })
        } 

怎么达到点击DIV显示img,在点击隐藏的效果

img

img

  • 写回答

1条回答 默认 最新

  • 渣渣与学霸 2022-04-28 09:05
    关注

    把外层函数去掉,当opacity为0时设为1,反则设为0,也可以用display控制显示隐藏

    $('#beijin').click(function(){
                        if($(this).css('opacity') ==0 ){
                        $(this).css('opacity', '1')
                    }else{
                        $(this).css('opacity','0');
                    }
                })
    
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 6月1日
  • 已采纳回答 5月24日
  • 创建了问题 4月27日

悬赏问题

  • ¥80 部署运行web自动化项目
  • ¥15 腾讯云如何建立同一个项目中物模型之间的联系
  • ¥30 VMware 云桌面水印如何添加
  • ¥15 用ns3仿真出5G核心网网元
  • ¥15 matlab答疑 关于海上风电的爬坡事件检测
  • ¥88 python部署量化回测异常问题
  • ¥30 酬劳2w元求合作写文章
  • ¥15 在现有系统基础上增加功能
  • ¥15 远程桌面文档内容复制粘贴,格式会变化
  • ¥15 这种微信登录授权 谁可以做啊