我正在使用流沙jQuery的此示例。

Making a Beautiful HTML5 Portfolio

现在,我想在单击图像时打开灯箱。为此,我正在使用fancybox jQuery。但是问题出在这个制作漂亮的HTML5 Portfolio(quicksand jQuery)示例图像在<Ul> <LI>标记中,而在fancybox jQuery示例中具有<p>标记。

我无法在ul li之间选择定位标记。

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8" />

        <title>Making a Beautiful HTML5 Portfolio | Tutorialzine Demo</title>

        <!-- Our CSS stylesheet file -->
        <link rel="stylesheet" href="assets/css/styles.css" />

        <!--[if lt IE 9]>
          <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
        <![endif]-->

        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
        <script>
            !window.jQuery && document.write('<script src="assets/js/jquery-1.4.3.min.js"><\/script>');
        </script>

        <script src="assets/js/jquery.quicksand.js"></script>
        <script src="assets/js/script.js"></script>

        <script type="text/javascript" src="./fancybox/jquery.fancybox-1.3.4.pack.js"></script>
        <link rel="stylesheet" type="text/css" href="./fancybox/jquery.fancybox-1.3.4.css" media="screen" />
        <link rel="stylesheet" type="text/css" href="./fancybox/style.css" />
        <script type="text/javascript">
            $(document).ready(function() {

                $("a#example2").fancybox({
                    'overlayShow'   : false,
                    'transitionIn'  : 'elastic',
                    'transitionOut' : 'elastic'
                });
                $("ul li a#example2").fancybox({
                    'overlayShow'   : false,
                    'transitionIn'  : 'elastic',
                    'transitionOut' : 'elastic'
                });


            });
        </script>
    </head>

    <body>

        <header>
            <h1>My Portfolio</h1>
        </header>

        <nav id="filter"></nav>

        <section id="container">
        <p>
        <a id="example2" href="assets/img/shots/1.jpg"><img src="assets/img/shots/1.jpg" alt="Illustration" /></a>
        </p>
        <p>
            <ul id="stage">
                <li data-tags="Print Design"><a id="example2" href="#"><img src="assets/img/shots/1.jpg" alt="Illustration" /></a></li>
                <li data-tags="Logo Design,Print Design"><img src="assets/img/shots/2.jpg" alt="Illustration" /></li>
                <li data-tags="Web Design,Logo Design"><img src="assets/img/shots/3.jpg" alt="Illustration" /></li>
                <li data-tags="Web Design,Print Design"><img src="assets/img/shots/4.jpg" alt="Illustration" /></li>
                <li data-tags="Logo Design"><img src="assets/img/shots/5.jpg" alt="Illustration" /></li>
                <li data-tags="Web Design,Logo Design,Print Design"><img src="assets/img/shots/6.jpg" alt="Illustration" /></li>
                <li data-tags="Logo Design,Print Design"><img src="assets/img/shots/7.jpg" alt="Illustration" /></li>
                <li data-tags="Web Design"><img src="assets/img/shots/8.jpg" alt="Illustration" /></li>
                <li data-tags="Web Design,Logo Design"><img src="assets/img/shots/9.jpg" alt="Illustration" /></li>
                <li data-tags="Web Design"><img src="assets/img/shots/10.jpg" alt="Illustration" /></li>
                <li data-tags="Logo Design,Print Design"><img src="assets/img/shots/11.jpg" alt="Illustration" /></li>
                <li data-tags="Logo Design,Print Design"><img src="assets/img/shots/12.jpg" alt="Illustration" /></li>
                <li data-tags="Print Design"><img src="assets/img/shots/13.jpg" alt="Illustration" /></li>
                <li data-tags="Web Design,Logo Design"><img src="assets/img/shots/14.jpg" alt="Illustration" /></li>
                <li data-tags="Print Design"><img src="assets/img/shots/15.jpg" alt="Illustration" /></li>
                <li data-tags="Logo Design"><img src="assets/img/shots/16.jpg" alt="Illustration" /></li>
                <li data-tags="Web Design,Logo Design,Print Design"><img src="assets/img/shots/17.jpg" alt="Illustration" /></li>
                <li data-tags="Web Design"><img src="assets/img/shots/18.jpg" alt="Illustration" /></li>
                <li data-tags="Web Design,Print Design"><img src="assets/img/shots/19.jpg" alt="Illustration" /></li>
                <li data-tags="Logo Design,Print Design"><img src="assets/img/shots/20.jpg" alt="Illustration" /></li>
                <li data-tags="Web Design,Logo Design"><img src="assets/img/shots/21.jpg" alt="Illustration" /></li>
                <li data-tags="Print Design"><img src="assets/img/shots/22.jpg" alt="Illustration" /></li>
                <li data-tags="Logo Design,Print Design"><img src="assets/img/shots/23.jpg" alt="Illustration" /></li>
            </ul>

        </section>

        <footer>
            <h2>Making a Beautiful HTML5 Portfolio</h2>
            <a class="tzine" href="http://tutorialzine.com/2011/06/beautiful-portfolio-html5-jquery/">Read &amp; Download on</a>
        </footer>



    </body>
</html>

在此代码中,P标签中的图像适用于高档包装盒,但在ul li标签中却不适用。

我认为问题在这里
<script type="text/javascript">
                $(document).ready(function() {

                    $("a#example2").fancybox({
                        'overlayShow'   : false,
                        'transitionIn'  : 'elastic',
                        'transitionOut' : 'elastic'
                    });
                    $("ul li a#example2").fancybox({
                        'overlayShow'   : false,
                        'transitionIn'  : 'elastic',
                        'transitionOut' : 'elastic'
                    });


                });
    </script>

整个代码http://fyels.in/Y95

最佳答案

固定它。

Fancybox不想在您的代码中使用流沙的原因是的主要原因是因为流沙插件的工作方式。流沙所做的操作(以便在重组可见结构时为元素设置动画)是克隆元素并将这些元素的副本注入(inject)DOM。改组完成后,与这些元素关联的所有事件都消失了。这就是为什么fancybox不适用于那些元素的原因。

quicksand plugin documentation(“与其他插件集成”部分)中描述了解决此问题的方法。它涉及将回调函数作为第二个元素传递给流沙。改组完成后,将立即执行该回调,在我们的示例中,它将负责查找并重新将fancybox应用于已改组的元素。

这是结合使用流沙和fancybox的工作示例:http://jsfiddle.net/E2vLq/29/

请注意有关代码的两件事:

  • LI的所有链接现在都具有fsand类(因此,我们不会一遍又一遍地使用相同的ID)。
  • 将回调传递给流沙,这会将fancybox重新应用到与a.fsand选择器匹配的所有元素。

  • 除了该之外,还有两个其他问题:
  • 对同一站点上的两个元素使用相同的ID(通常,根据html规范,这是禁止的)。
  • 您在UL之后无法关闭段落元素。
  • 09-27 04:31