关于点击时画廊缩略图的建议?

发布于 2024-11-18 19:57:27 字数 2065 浏览 6 评论 0原文

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

谢谢 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>

代码

.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;
}

I'm trying to build an image gallery with thumbnails and a display for a larger image. At present, its working when the the mouse hovers over the thumbnail which displays the larger image. However I wish to replace the hover feature with an on click so that the larger image does not disappear when the mouse leaves the thumbnail. From a bit of research I'm lead to believe that this can not be done with css as with the hover feature and that I would need to include some script. As I'm new to web development after this I'm a bit lost and would appreciate some help. Below is the html code for the gallery container and the corresponding css code......where do I start from here?

Thanks
A

html code

<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 code

.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;
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

可遇━不可求 2024-11-25 19:57:27

这是一个简单的 jquery 开始。

http://jsfiddle.net/8GKXM/

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

这就是 jquery 基本上所说的:

在每个单独的 .thumbnail 点击上:

隐藏 .thumbnail 范围(就像它找到的每个范围一样)
然后
找到单击的 .thumbnail 的跨度并显示


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

Heres a simple start with jquery.

http://jsfiddle.net/8GKXM/

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

This is what the jquery says basically:

On every individual .thumbnail click:

hide .thumbnail span ( as in every span it finds )
then
find clicked .thumbnail's span and show that


I would probably move the bigger images into their own container though...

夏日浅笑〃 2024-11-25 19:57:27

您可以将 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'}    
  });
 });
});

You can use jQuery along with blockUI plugin:

<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>

And then you can use the window onload event to attach the onclick event to fire the large image with blockUI:

$(function(){
 $(".imgthumb").onclick(function() {
  $.blockUI({
   message: "<div><img src=" + $(this + " > img").attr("src") + " width='405' height='585' /></div>";
   css: { border: '1px solid grey'}    
  });
 });
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文