onclick 在弹出框中显示图像
我制作了一个简单的画廊,使用这个脚本来显示图像:
$rs = mysql_query('SELECT * FROM images WHERE oferta_id=2');
while($row = mysql_fetch_array($rs))
{
echo '<li onclick="Large()"><img src='.$row['location'].' alt="image"/></li>';
}
并且我想以一种方式使用javascript,当用户单击某个图片时,会弹出一个框,他会看到更大的图片。我想我在在
标记中使用 onclick
的正确方法,但几乎不知道如何创建 Large()
函数。有帮助吗关于主题?谢谢勒伦
I made a simple gallery, using this script to show the images:
$rs = mysql_query('SELECT * FROM images WHERE oferta_id=2');
while($row = mysql_fetch_array($rs))
{
echo '<li onclick="Large()"><img src='.$row['location'].' alt="image"/></li>';
}
and I want to use javascript in a way that when an user click on a certain picture a box pops-up and he sees the picture larger.I think I'm on a right way using onclick
in the <li>
tag, but have almost no idea how to make the Large()
function.Any help on the topic?
Thanks
Leron
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
你可以给每个<图像>一个递增的数字 ID,并将其传递给 Large 函数,即
每个图像都
可以在 Large 函数中获得对该特定图像的唯一引用。
即
或如已经建议的那样,您可以使用灯箱。
另外,另一种选择是仅将 onclick 处理程序添加到图像并传递它,然后您也可以直接引用图像,并删除中间人。
即
只是一些值得深思的东西
You could give each < img > an incrementing numeric id, and be passing that to the Large function, i.e.
and each image would be
so that you can get a unique reference to that particular image within the large function.
i.e.
or as has already been suggested, you can use lightbox.
Also, another option is to just add the onclick handler the image and pass this, and then you have a direct reference to the image as well, and cut out the middle man, as it were.
i.e.
just some food for thought
我只是使用 jquery 插件或另一个 javascript 框架的插件。在 google 上搜索“jquery lightbox”并查看示例。
除非您需要一些现有的特定功能,或者希望构建自己的功能作为学习练习,否则编写自己的功能绝对没有意义。
i'd just use a jquery plugin or another javascript framework's plugin. do a google search for "jquery lightbox" and see examples.
there's definitely no point in writing your own unless you need some specific functionality not available out there or are looking to build your own as a learning exercise.
我建议您查看数百个灯箱选项以获得更大的图像。只是谷歌灯箱。
I would suggest checking out the 100s of lightbox options for your larger image. Just google lightbox.