Qtip question via iFrame - With JQUERY LIVE

I would like to find a fay for using Qtip in an iFrame on my page. I found a way to use QTIP for an iframe, but not with JQUERY LIVE ....

q Run iFrame: http://craigsworks.com/projects/forums/thread-question-qtip-through-iframe

Any ideas on how to apply JQUERY Live to this?

My current code is:

$('iframe').load(function(){
  $(this).qtip(
  {
    content: 'My first Qtip! Look mom!',
    show: {
      when : {
         target: $(this).contents().find('.tipoff') // Element within the iframe
      }
    },
    hide: {
      when : {
         target: $(this).contents().find('.tipoff') // Element within the iframe
      }
    }
  });
});

thank

+3
source share
1 answer

, , - , . , , , , , qTip <iframe>, .

live(), iFrame jQuery (live?), , :

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Title</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <style type="text/css">
        iframe {
            border:1px dashed red;
        }
    </style>
    <link rel="stylesheet" type="text/css" href="jquery.qtip.min.css"/>
    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>
    <script src="jquery.qtip.min.js"></script>
    <script type="text/javascript">

        $(function() {
            $('p a.tip').qtip({
                content: 'foo'
            });

            $('iframe').load(function() {
                var position = $(this).position();
                var top = position.top;
                var left = position.left;
                $(this.contentDocument).find('p a.tip').qtip({
                    content: 'bar',
                    position: { adjust: { x:left, y:top } }
                });
            });

            $('#click').click(function(){
                $('iframe').attr('src', 'test.html');
                return false;
            });
        });

    </script>
</head>
<body>
    <p><a class="tip" href="#">Lorem ipsum dolor</a> sit amet, consectetur adipiscing elit.</a></p>
    <iframe></iframe>
    <p><a href="#" id="click">Load iFrame</a></p>
</body>
</html>

test.html :

<p><a class="tip" href="#">Duis massa metus</a>, convallis vitae, mollis vel, feugiat vitae, nunc.</p>

jquery.qtip.min.css jquery.qtip.min.js qTip2.

: , - ( ), .

, -!: -)

+1

Source: https://habr.com/ru/post/1741355/


All Articles