Search code examples
javascriptjqueryhtmlcsszeroclipboard

display: inline; doesn't work with copy link


Can you explain me why only the third "copy link" works only if all panels are closed ?
I want my copy link works when it's in a panel and when a panel is open too.

HERE IS MY PAGE: http://500milligrammes.com/facticemagazine/final/0/

JSFIDDLE

HERE IS MY CODE:

<!DOCTYPE HTML>
<!--[if IE 8]><html lang="en" class="lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!-->
<html lang="en">
<!--<![endif]-->

<head>
    <meta charset="utf-8">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <script type="text/javascript" src="https://code.jquery.com/jquery-2.1.0.js"></script>

    <style>
        .panel1,
        .panel2 {
            display: none;
            border: 1px solid #ccc;
            background-color: #eee
        }

        .flip1,
        .flip2 {
            border: 1px solid #ccc;
            background-color: #eee
        }

        #check,
        #check2 {
            visibility: hidden;
            width: 12px;
            height: 12px;
        }

        span#copy-callbacks,
        span#copy-callbacks2 {
            float: none;
            cursor: pointer;
        }
    </style>
    <script type="text/javascript">
        $(document).ready(function() {
            $("span#copy-callbacks").zclip({
                path: "ZeroClipboard.swf",
                copy: $('#callback-paragraph').text(),
                beforeCopy: function() {
                    $('#copy-callbacks').css('background', 'none');
                },
                afterCopy: function() {
                    $('#copy-callbacks').css('background', 'none');
                }
            });

            document.getElementById("copy-callbacks").onclick = function() {
                document.getElementById("check").style.visibility = "visible";
            }
        });


        $(document).ready(function() {
            $('span#copy-callbacks').hover(
                function() {
                    $(this).css({
                        "color": "#e0ccb4"
                    });
                },

                function() {
                    $(this).css({
                        "color": "#000"
                    });
                }
            );




            $("span#copy-callbacks2").zclip({
                path: "ZeroClipboard.swf",
                copy: $('#callback-paragraph2').text(),
                beforeCopy: function() {
                    $('#copy-callbacks2').css('background', 'none');
                },
                afterCopy: function() {
                    $('#copy-callbacks2').css('background', 'none');
                }
            });

            document.getElementById("copy-callbacks2").onclick = function() {
                document.getElementById("check2").style.visibility = "visible";
            }
        });


        $(document).ready(function() {
            $('span#copy-callbacks2').hover(
                function() {
                    $(this).css({
                        "color": "#e0ccb4"
                    });
                },

                function() {
                    $(this).css({
                        "color": "#000"
                    });
                }
            );




            $(".flip1").click(function() {
                $(".panel1").slideToggle("fast");
            });

            $(".flip2").click(function() {
                $(".panel2").slideToggle("fast");
            });
        });
    </script>
</head>

<body>





    <div class="flip1">Click to slide the first panel down or up</div>
    <div class="panel1">

        when this panel is open, any copy link works !!!

    </div>





    <div style="margin-top:150px;" class="flip2">Click to slide the second panel down or up</div>
    <div class="panel2">
        when a copy link is inside a panel, it doesn't work !!!
        <br/>
        <br/>

        <span id="copy-callbacks">Copy link&nbsp;&nbsp;<img  src="check.png" id="check" style="display: inline;"></span>
        <span style="font-size:0px;" id="callback-paragraph">essaie sans alert</span>

    </div>





    <div style="margin-top:150px; ">
        This one works perfectly when all panels are closed !!
        <br/>
        <span id="copy-callbacks2">Copy link&nbsp;&nbsp;<img  src="check.png" id="check2" style="display: inline;"></span>
        <span style="font-size:0px;" id="callback-paragraph2">essaie sans alert</span>
    </div>





    <script type="text/javascript" src="jquery.zclip.js"></script>
    <script type="text/javascript" src="jquery.cbpFWSlider.min.js"></script>
</body>

</html>

Solution

  • ZClip adds an absolutely positioned flash (swf) object which clings to the bottom and when your panels are closed the zclip object container covers the third link and you can't click on it. See your updated fiddle, I put a border around zclip and you can see that it's right over the link: http://jsfiddle.net/4x3qctno/2/

    When you open panels it pushes third link down, but the zclip container stays in the same place and so your link works then.

    To fix this, change z-index of zclip object container in CSS like so:

    .zclip{
        z-index:-1000!important;
    }