【问题标题】:Suggestion for gallery thumbnail on click?点击画廊缩略图的建议?
【发布时间】:2011-09-29 12:25:22
【问题描述】:

我正在尝试构建一个带有缩略图和显示更大图像的图片库。目前,当鼠标悬停在显示较大图像的缩略图上时,它的工作。但是,我希望用单击替换悬停功能,以便在鼠标离开缩略图时较大的图像不会消失。通过一些研究,我相信这不能像悬停功能那样使用 css 来完成,我需要包含一些脚本。由于在此之后我是 Web 开发的新手,所以我有点迷茫,希望能得到一些帮助。下面是gallery容器的html代码和对应的css代码......从这里开始呢?

谢谢 一个

html代码

<div class="gallerycontainer">

    <a class="thumbnail" href="#thumb"><img src="images/gallery/1one/101.jpg" width="56px" height="80px" border="0" /><span><img src="images/gallery/1one/101.jpg" width="405px" height="585px"/></span></a>

    <a class="thumbnail" href="#thumb"><img src="images/gallery/1one/102.jpg" width="56px" height="80px" border="0" /><span><img src="images/gallery/1one/102.jpg" width="405px" height="585px"/></span></a>

<a class="thumbnail" href="#thumb"><img src="images/gallery/1one/103.jpg" width="56px" height="80px" border="0" /><span><img src="images/gallery/1one/103.jpg" width="405px" height="585px"/></span></a>

<a class="thumbnail" href="#thumb"><img src="images/gallery/1one/104.jpg" width="56px" height="80px"border="0" /><span><img src="images/gallery/1one/104.jpg" width="405px" height="585px"/></span></a>

<br />

</div>

css代码

.gallerycontainer{
position: absolute;
/*Add a height attribute and set to largest image's height to prevent overlaying*/
}

.thumbnail img{
border: 1px solid white;
margin: 0 5px 5px 0;
}

.thumbnail:hover{
background-color: transparent;
}

.thumbnail:hover img{
border: 1px solid grey;
}

.thumbnail span{ /*CSS for enlarged image*/
position: absolute;
background-color: #000000;
padding: 5px;
left: -1000px;
border: none;
visibility: hidden;
color: black;
text-decoration: none;
}

.thumbnail span img{ /*CSS for enlarged image*/
border-width: 0;
padding: 2px;
}

.thumbnail:hover span{ /*CSS for enlarged image*/
visibility: visible;
top: 0;
left: 300px; /*position where enlarged image should offset horizontally */
z-index: 50;
}

【问题讨论】:

  • 下次请使用代码功能,否则您的代码将无法正确显示在屏幕上。

标签: html css gallery thumbnails


【解决方案1】:

这是一个简单的 jquery 开始。

http://jsfiddle.net/8GKXM/

$('.thumbnail').each(function(){
    $(this).click(function() {
        $('.thumbnail span').hide();
       $(this).find('span').show('slow');
    });
});

jquery 基本上是这样说的:

在每个单独的 .thumbnail 点击:

隐藏 .thumbnail 跨度(在它找到的每个跨度中) 然后 找到点击的 .thumbnail 的跨度并显示出来


我可能会将较大的图像移动到它们自己的容器中...

【讨论】:

    【解决方案2】:

    您可以将jQueryblockUI 插件一起使用:

    <div class="gallerycontainer">
        <a class="thumbnail" href="#thumb" class="imgthumb"><img src="images/gallery 
            /1one/101.jpg" width="56px" height="80px" border="0" /></a>
        <a class="thumbnail" href="#thumb" class="imgthumb"><img src="images/gallery
            /1one/102.jpg" width="56px" height="80px" border="0" /></a>
    </div>
    

    然后您可以使用窗口onload 事件附加onclick 事件以使用blockUI 触发大图像:

    $(function(){
     $(".imgthumb").onclick(function() {
      $.blockUI({
       message: "<div><img src=" + $(this + " > img").attr("src") + " width='405' height='585' /></div>";
       css: { border: '1px solid grey'}    
      });
     });
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-10-25
      • 1970-01-01
      • 1970-01-01
      • 2018-04-25
      • 1970-01-01
      • 2013-09-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多