jquery - 隐藏和显示 div onclick svg

标签 jquery html svg

<polygon id="triangle" fill="none" stroke="#EB9381" stroke-miterlimit="10" points="66.233,110.916 114.721,83 66.233,55.083  "/>
<g id="rectangle">
    <rect x="90.908" y="64.82" fill="none" stroke="#EB9381" stroke-miterlimit="10" width="5" height="38" />
    <rect x="71.908" y="64.82" fill="none" stroke="#EB9381" stroke-miterlimit="10" width="5" height="38"/>
</g>

这是我的 jquery.我想做的是在单击时隐藏三角形 id="triangle",并显示矩形。我尝试过悬停效果,它确实有效。但使用点击选项却没有,我不知道为什么。

function hoverplayer()
{
    $('#rectangle').hide();
    $('#cercle_tourne').click(
        function()
        {
            $('#triangle').hide();
        },
        function()
        {
            $('#rectangle').show();
        }
    );
}

最佳答案

您可以尝试以下方法!但请确保“cercle_tourne”是一个容器或按钮。单击它时,它将显示控件(三角形),第二次单击时,它将隐藏它。

$('#cercle_tourne').click(function(){
    if($('#triangle').css('display') == 'none'){
        $('#triangle').show();
    }else{
        $('#triangle').hide();
    }
});

希望以上内容对您有所帮助。

关于jquery - 隐藏和显示 div onclick svg,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31990050/

相关文章:

javascript - 如何给网页添加视差效果?

javascript - 根据元素的属性过滤 dom 树的最有效方法是什么?

javascript - 根据鼠标位置自动滚动 div

javascript - iFrame 不可编辑(wysiwyg javascript)

javascript - 捕捉 svg 动态 : wrong positioning

css - 使用 CSS 定位/选择 SVG 中的 animateTransform 元素

javascript - 在 D3 图上隐藏一条线

javascript - PHP 如何刷新 HTML 代码中的 ProgressBar?

javascript - 纯javascript中的jquery position()

html - 即使在隐藏侧边栏时,也使 div 子元素占据 div 父元素的 100%