简体   繁体   English

如何创建Google图像引擎效果?

[英]How to Create Google images engine effect?

I am trying to create google image engine effect that shows images credits when user hovers the image (enlarge the image and show credits). 我正在尝试创建谷歌图像引擎效果,当用户悬停图像时显示图像信用(放大图像和显示信用)。 I am not sure how to pop the image up and ignore the flow of the contents. 我不知道如何弹出图像并忽略内容的流动。

I know lightbox would do the similar effect but all I need is a simple hover and show images credits effect. 我知道灯箱会做类似的效果,但我只需要一个简单的悬停和显示图像信用效果。 I have search google and all I got are popup plugins like lightbox. 我有搜索谷歌,我得到的是像灯箱一样的弹出插件。 I was wondering if anyone give me a direction or tutorial for that? 我想知道是否有人给我指导或教程? Thanks a lot. 非常感谢。

This will show a div floating above the div container for the image. 这将显示一个div浮动在图像的div容器上方。

<div id="yourImage1Parent"><img id"yourImage1" src="yourImage1src.jpg" /></div>
<script type="javascript/text">
 var credits = document.createElement("div");
 credits.style = "position: absolute; height:25px; width: 25px";
 credits.innerHTML = //load credits from ajax or array or logic, maybe from data-attribute
 document.getElementById("yourImage1Parent").appendChild(credits);
</script>

However, it is simplistic. 但是,这很简单。 It needs an event to be wired up for controlling the viewing of this element and removal of the element. 它需要连接一个事件来控制该元素的查看和元素的移除。 Since there was no actual code for an example, this code is just an example. 由于示例中没有实际代码,因此该代码只是一个示例。

I have created a basic example which enlarges the image and show the box. 我创建了一个基本的例子,它放大图像并显示框。 To make this a general solution, some finer javascript is needed. 为了使这成为一般解决方案,需要一些更精细的JavaScript。

I create a invisible div containing an img element with the same image. 我创建了一个包含具有相同图像的img元素的不可见div。 In the onmouseover event of the original img element i start a timer, which shows the div with the duplicate img element. 在原始img元素的onmouseover事件中,我启动一个计时器,它显示带有重复img元素的div。 When the div is shown, another timer is started. 显示div时,启动另一个计时器。 When the timer fires I change the size and position of the div and the size of the image in the div. 当计时器触发时,我改变了div的大小和位置以及div中图像的大小。 By using CSS3 Transistions the browser will automatically make the size-change into an animation which looks like a zoom. 通过使用CSS3 Transistions,浏览器将自动将大小更改为一个看起来像缩放的动画。

I have tested my code in Chrome but it should also function in Firefox and Opera. 我在Chrome中测试了我的代码,但它也应该在Firefox和Opera中运行。 IE will not show the animation. IE不会显示动画。

Link: Here 链接: 这里

Use my source as a starting point. 使用我的来源作为起点。

EDIT: I have written a better version of the code which takes all images that have the class thumbs and makes them zoom. 编辑:我已经编写了一个更好的代码版本,它采用了具有类拇指的所有图像并使它们变焦。 This version is a bit more complicated than the old one. 这个版本比旧版本复杂一点。 Again, take a look at the source and feel free to ask questions in the commentaries below. 再次,看看源代码,并随时在下面的评论中提问。

Link: Here 链接: 这里

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM