代码之家  ›  专栏  ›  技术社区  ›  Sergey Ryabov

fancyBox中的重复图像

  •  1
  • Sergey Ryabov  · 技术社区  · 8 年前

    我有一个fancyBox,它工作得很好,除了在某些图像上,它会多次滑动相同的图像。这是 web page .

    我不使用任何其他jQuery或我自己的脚本,只使用fancyBox脚本。

    下面是我正在使用的代码:

    /*! fancyBox v2.1.5 fancyapps.com | fancyapps.com/fancybox/#license */
    .fancybox-wrap,
    .fancybox-skin,
    .fancybox-outer,
    .fancybox-inner,
    .fancybox-image,
    .fancybox-wrap iframe,
    .fancybox-wrap object,
    .fancybox-nav,
    .fancybox-nav span,
    .fancybox-tmp
    {
    	padding: 0;
    	margin: 0;
    	border: 0;
    	outline: none;
    	vertical-align: top;
    }
    
    .fancybox-wrap {
    	position: absolute;
    	top: 0;
    	left: 0;
    	z-index: 8020;
    }
    
    .fancybox-skin {
    	position: relative;
    	background: #f9f9f9;
    	color: #444;
    	text-shadow: none;
    	-webkit-border-radius: 4px;
    	   -moz-border-radius: 4px;
    	        border-radius: 4px;
    }
    
    .fancybox-opened {
    	z-index: 8030;
    }
    
    .fancybox-opened .fancybox-skin {
    	-webkit-box-shadow: 0 10px 25px rgba(0, 0, 0, 0.5);
    	   -moz-box-shadow: 0 10px 25px rgba(0, 0, 0, 0.5);
    	        box-shadow: 0 10px 25px rgba(0, 0, 0, 0.5);
    }
    
    .fancybox-outer, .fancybox-inner {
    	position: relative;
    }
    
    .fancybox-inner {
    	overflow: hidden;
    }
    
    .fancybox-type-iframe .fancybox-inner {
    	-webkit-overflow-scrolling: touch;
    }
    
    .fancybox-error {
    	color: #444;
    	font: 14px/20px "Helvetica Neue",Helvetica,Arial,sans-serif;
    	margin: 0;
    	padding: 15px;
    	white-space: nowrap;
    }
    
    .fancybox-image, .fancybox-iframe {
    	display: block;
    	width: 100%;
    	height: 100%;
    }
    
    .fancybox-image {
    	max-width: 100%;
    	max-height: 100%;
    }
    
    #fancybox-loading, .fancybox-close, .fancybox-prev span, .fancybox-next span {
    	background-image: url('fancybox_sprite.png');
    }
    
    #fancybox-loading {
    	position: fixed;
    	top: 50%;
    	left: 50%;
    	margin-top: -22px;
    	margin-left: -22px;
    	background-position: 0 -108px;
    	opacity: 0.8;
    	cursor: pointer;
    	z-index: 8060;
    }
    
    #fancybox-loading div {
    	width: 44px;
    	height: 44px;
    	background: url('fancybox_loading.gif') center center no-repeat;
    }
    
    .fancybox-close {
    	position: absolute;
    	top: -18px;
    	right: -18px;
    	width: 36px;
    	height: 36px;
    	cursor: pointer;
    	z-index: 8040;
    }
    
    .fancybox-nav {
    	position: absolute;
    	top: 0;
    	width: 40%;
    	height: 100%;
    	cursor: pointer;
    	text-decoration: none;
    	background: transparent url('blank.gif'); /* helps IE */
    	-webkit-tap-highlight-color: rgba(0,0,0,0);
    	z-index: 8040;
    }
    
    .fancybox-prev {
    	left: 0;
    }
    
    .fancybox-next {
    	right: 0;
    }
    
    .fancybox-nav span {
    	position: absolute;
    	top: 50%;
    	width: 36px;
    	height: 34px;
    	margin-top: -18px;
    	cursor: pointer;
    	z-index: 8040;
    	visibility: hidden;
    }
    
    .fancybox-prev span {
    	left: 10px;
    	background-position: 0 -36px;
    }
    
    .fancybox-next span {
    	right: 10px;
    	background-position: 0 -72px;
    }
    
    .fancybox-nav:hover span {
    	visibility: visible;
    }
    
    .fancybox-tmp {
    	position: absolute;
    	top: -99999px;
    	left: -99999px;
    	visibility: hidden;
    	max-width: 99999px;
    	max-height: 99999px;
    	overflow: visible !important;
    }
    
    /* Overlay helper */
    
    .fancybox-lock {
        overflow: hidden !important;
        width: auto;
    }
    
    .fancybox-lock body {
        overflow: hidden !important;
    }
    
    .fancybox-lock-test {
        overflow-y: hidden !important;
    }
    
    .fancybox-overlay {
    	position: absolute;
    	top: 0;
    	left: 0;
    	overflow: hidden;
    	display: none;
    	z-index: 8010;
    	background: url('fancybox_overlay.png');
    }
    
    .fancybox-overlay-fixed {
    	position: fixed;
    	bottom: 0;
    	right: 0;
    }
    
    .fancybox-lock .fancybox-overlay {
    	overflow: auto;
    	overflow-y: scroll;
    }
    
    /* Title helper */
    
    .fancybox-title {
    	visibility: hidden;
    	font: normal 13px/20px "Helvetica Neue",Helvetica,Arial,sans-serif;
    	position: relative;
    	text-shadow: none;
    	z-index: 8050;
    }
    
    .fancybox-opened .fancybox-title {
    	visibility: visible;
    }
    
    .fancybox-title-float-wrap {
    	position: absolute;
    	bottom: 0;
    	right: 50%;
    	margin-bottom: -35px;
    	z-index: 8050;
    	text-align: center;
    }
    
    .fancybox-title-float-wrap .child {
    	display: inline-block;
    	margin-right: -100%;
    	padding: 2px 20px;
    	background: transparent; /* Fallback for web browsers that doesn't support RGBa */
    	background: rgba(0, 0, 0, 0.8);
    	-webkit-border-radius: 15px;
    	   -moz-border-radius: 15px;
    	        border-radius: 15px;
    	text-shadow: 0 1px 2px #222;
    	color: #FFF;
    	font-weight: bold;
    	line-height: 24px;
    	white-space: nowrap;
    }
    
    .fancybox-title-outside-wrap {
    	position: relative;
    	margin-top: 10px;
    	color: #fff;
    }
    
    .fancybox-title-inside-wrap {
    	padding-top: 10px;
    }
    
    .fancybox-title-over-wrap {
    	position: absolute;
    	bottom: 0;
    	left: 0;
    	color: #fff;
    	padding: 10px;
    	background: #000;
    	background: rgba(0, 0, 0, .8);
    }
    
    /*Retina graphics!*/
    @media only screen and (-webkit-min-device-pixel-ratio: 1.5),
    	   only screen and (min--moz-device-pixel-ratio: 1.5),
    	   only screen and (min-device-pixel-ratio: 1.5){
    
    	#fancybox-loading, .fancybox-close, .fancybox-prev span, .fancybox-next span {
    		background-image: url('fancybox_sprite@2x.png');
    		background-size: 44px 152px; /*The size of the normal image, half the size of the hi-res image*/
    	}
    
    	#fancybox-loading div {
    		background-image: url('fancybox_loading@2x.gif');
    		background-size: 24px 24px; /*The size of the normal image, half the size of the hi-res image*/
    	}
    }
    #albums-bar-shape {
        width: 1141px;
        height: 25px;
        margin: 0 auto 0px auto;
        position: relative;
        /*background-color: #e7e7e7;*/
    }
    
    #album {
        width: 1150px;
        height: 850px;
        margin: 0 auto 30px auto;
        position: relative;
        /*background-color: #afd9ee;*/
        top: 20px;
    }
    
    .albums-bar {
        position: relative;
        float: right;
        left: -50%;
    }
    
    .albums-bar ul {
        list-style: none;
        position: relative;
        left: 50%;
    }
    
    .albums-bar li {
        float: left;
        margin-right: 50px;
        list-style-type: none;
    }
    
    .albums-bar a {
        color: #8c8c8c;
        font-size: 13pt;
        font-family: "Segoe UI", "Arial", "Courier New";
        text-decoration: none;
    }
    
    .albums-bar a:hover {
        color: #222222;
        padding-bottom: 1px;
        border-bottom: 2px solid #222222;
        text-decoration: none;
    }
    
    #selected-album {
        color: #222222;
        padding-bottom: 1px;
        border-bottom: 2px solid #222222;
    }
    /*Vertical photos formatting*/
    div.img {
        margin: 5px;
        border: 1px solid #ccc;
        float: left;
        width: 275px;
    }
    
    div.img:hover {
        border: 1px solid #777;
    }
    
    div.img img {
        width: 100%;
        height: auto;
    }
    /*Horizontal photos formatting*/
    div.img-wide {
        margin: 5px;
        border: 1px solid #ccc;
        float: left;
        width: 370px;
    }
    
    div.img-wide:hover {
        border: 1px solid #777;
    }
    
    div.img-wide img {
        width: 100%;
        height: auto;
    }
    
    article, aside, figure, footer, header, hgroup,
    menu, nav, section { display: block; }
    
    body {
        margin: 0px;
        padding: 0px;
        background-image: url(images/img-noise-361x370.png (1));
        background-repeat: repeat;
    }
    
    #top {
        width: 650px;
        height: 120px;
        margin: 0 auto 30px auto;
        /*background-color: #e7e7e7;*/
    }
    
    #menu-bar {
        position: relative;
        float: right;
        left: -50%;
    }
    
    #menu-bar ul {
        list-style: none;
        position: relative;
        left: 50%;
        margin-top: 10px;
    }
    
    #menu-bar li {
        float: left;
        position: relative;
        margin-right: 55px;
    }
    
    #menu-bar a {
        color: #8c8c8c;
        font-size: 12pt;
        font-family: "Segoe UI", "Arial", "Courier New";
        text-decoration: none;
    }
    
    #selected {
        color: #000000;
    }
    
    #selected > a {
        color: #000000;
    }
    
    #menu-bar a:hover {
        color: #222222;
        text-decoration: none;
    }
    
    #images {
        width: 533px;
        height: 800px;
        margin: 0 auto 30px auto;
        position: relative;
        /*background-color: #afd9ee;*/
    }
    
    #logo {
        width: 650px;
        height: auto;
        margin: 30px auto 30px auto;
        display: block;
    }
    
    /* Dropdown Button */
    .dropbtn {
        cursor: pointer;
        color: #8c8c8c;
        font-size: 12pt;
        font-family: "Segoe UI", "Arial", "Courier New";
        text-decoration: none;
        margin-bottom: 5px;
        /*background: #dddddd;*/
    }
    
    /* The container <div> - needed to position the dropdown content */
    .dropdown {
        position: relative;
        display: inline-block;
    }
    
    /* Dropdown Content (Hidden by Default) */
    .dropdown-content {
        display: none;
        position: absolute;
        min-width: 160px;
    }
    
    /* Links inside the dropdown */
    .dropdown-content a {
        color: 8c8c8c;
        text-decoration: none;
        display: block;
        font-size: 10pt !important;
        margin-bottom: 2px;
    }
    
    /* Change color of dropdown links on hover */
    .dropdown-content a:hover {
        color: #000000;
    }
    
    /* Show the dropdown menu on hover */
    .dropdown:hover .dropdown-content {
        display: block;
    }
    
    /* Change the background color of the dropdown button when the dropdown content is shown */
    .dropdown:hover .dropbtn {
        color: #565656;
    }
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <link rel="stylesheet" type="text/css" href="../../css/custom.css">
        <link rel="stylesheet" type="text/css" href="../../css/dropdown.css">
        <link rel="stylesheet" type="text/css" href="../../css/crossfade.css">
        <link rel="stylesheet" type="text/css" href="../../css/portfolio.css">
        <link rel="stylesheet" href="../../src/css/bootstrap.min.css"/>
        <title>Car Photos</title>
        <!--[if IE]>
        <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
        <![endif]-->
        <!-- Add jQuery library -->
        <script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>
        <!-- Add fancyBox -->
        <link rel="stylesheet" href="../../source/jquery.fancybox.css" type="text/css" media="screen" />
        <script type="text/javascript" src="../../source/jquery.fancybox.pack.js"></script>
        <script type="text/javascript">
            $(document).ready(function() {
                $(".fancybox").fancybox();
            });
        </script>
    </head>
    <body>
        <img id="logo" src="http://feanor.cz/images/logo_studio.gif">
        <div id="top">
            <div id="menu-bar">
                <ul>
                    <li><a href="http://feanor.cz/">Home</a></li>
                    <li class="dropdown">
                        <a href="http://feanor.cz/portfolio/fashion-photo">Photo</a>
                        <div class="dropdown-content">
                            <a href="http://feanor.cz/portfolio/fashion-photo">Fashion portraits</a>
                            <a href="http://feanor.cz/portfolio/art-photo">Art portraits</a>
                            <a href="http://feanor.cz/portfolio/product-photo">Product photography</a>
                            <a href="http://feanor.cz/portfolio/interior-photo">Interior photography</a>
                        </div>
                    </li>
                    <li><a href="#">Paintings</a></li>
                    <li><a href="http://feanor.cz/contacts">Contact</a></li>
                    <li><a href="http://feanor.cz/about">About Us</a></li>
                </ul>
            </div>
        </div>
        <div id="albums-bar-shape">
            <div class="albums-bar">
                <ul>
                    <li><a href="http://feanor.cz/portfolio/fashion-photo">Fashion portraits</a></li>
                    <li><a href="http://feanor.cz/portfolio/art-photo">Art portraits</a></li>
                    <li><a id="selected-album" href="#">Car photography</a></li>
                    <li><a href="http://feanor.cz/portfolio/product-photo">Product photography</a></li>
                    <li><a href="http://feanor.cz/portfolio/interior-photo">Interior photography</a></li>
                </ul>
            </div>
        </div>
        <div id="album">
            <div class="img-wide">
                <a class="fancybox" rel="group" href="1.jpg">
                    <img src="1.jpg" alt="image 1" width="300" height="200">
                </a>
            </div>
            <div class="img-wide">
                <a class="fancybox" rel="group" href="2.jpg">
                    <img src="2.jpg" alt="image 2" width="300" height="200">
                </a>
            </div>
            <div class="img-wide">
                <a class="fancybox" rel="group" href="6.jpg">
                    <img src="6.jpg" alt="image 3" width="300" height="200">
            </div>
            <div class="img-wide">
                <a class="fancybox" rel="group" href="4.jpg">
                    <img src="4.jpg" alt="image 4" width="300" height="200">
                </a>
            </div>
            <div class="img-wide">
                <a class="fancybox" rel="group" href="5.jpg">
                    <img src="5.jpg" alt="image 5" width="300" height="200">
                </a>
            </div>
            <div class="img-wide">
                <a class="fancybox" rel="group" href="3.jpg">
                    <img src="3.jpg" alt="image 6" width="300" height="200">
            </div>
            <div class="img-wide">
                <a class="fancybox" rel="group" href="7.jpg">
                    <img src="7.jpg" alt="image 7" width="300" height="200">
                </a>
            </div>
            <div class="img-wide">
                <a class="fancybox" rel="group" href="8.jpg">
                    <img src="8.jpg" alt="image 8" width="300" height="200">
                </a>
            </div>
        </div>
    </body>
    </html>
    1 回复  |  直到 8 年前
        1
  •  2
  •   jgoley    8 年前

    您忘记关闭一些锚标记#6和#3。 因此,浏览器添加了另一个链接,使fancyBox认为存在重复图像。以下是Chrome如何编译代码:

    enter image description here