旋转图像和文本
我希望在我的网站上每隔几秒钟旋转一张图像及其相应的文本块。就像这些人 http://hellofisher.com/
我知道我可以使用 javascript 来旋转图像,但我还没有找不到可以让文本块同时旋转以适应图像的地方。
I want to have an image with it's corresponding block of text rotating every few seconds on my website. Just like these guys http://hellofisher.com/
I know I can get a javascript to rotate the images but I haven't found where I can have the block of text alongside rotating to suit the images.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
只需谷歌搜索 jquery 内容旋转器或内容滑块即可。有一百万个现成的插件已经这样做了:
例如
Just google for jquery content rotators or content sliders. There's a million ready-made plugins already done like this:
For example
我将向您展示一个简单的示例,您可以轻松地在您的网站上使用它。此示例使用 3 张幻灯片,并不是动态滑块,您可以拥有任意数量的幻灯片,但如果幻灯片数量可以变化,则可以轻松将其编辑为一张幻灯片。
HTML:
滑块是用户可以看到的可见区域,滑块区域是放置幻灯片的区域,每张幻灯片包含不同的图像和文本。
CSS:
如您所见,滑块区域的宽度是滑块大小的 3 倍,因为有 3 张幻灯片。滑块有overflow:hidden,这意味着滚动条不可见,还有position:relative,这样我们就可以绝对地将滑块区域定位在滑块内。然后我们只需将幻灯片插入滑块区域即可。
JS(使用 JQuery):
在这里您设置一个计时器,它将每 5 秒调用一次changeSlide 函数。 ChangeSlide 函数将获取滑块滚动条的当前位置并相应地设置动画。如果显示最后一张幻灯片,下一张将是第一张幻灯片 (pos=0),如果不显示最后一张幻灯片,则会在位置上添加 400,以便滚动到下一张幻灯片。基本上,滑动动画只是用计时器移动隐藏的滚动条。
希望这有帮助!
I'll show you a simple example which you can easily use on your site. This example uses 3 slides and isn't a dynamic slider where you can have as many slides as you want to but it's easy to edit it into one if the amount of slides can vary.
HTML:
Slider is the visible area which the user can see, slider-area is the area where you put the slides and each slide contains a different image and text.
CSS:
As you can see, slider-area's width is 3 times the size of slider because there are 3 slides. Slider has overflow: hidden which means scrollbar won't be visible and position: relative so that we can absolutely position the slider-area inside the slider. Then we simply insert slides inside the slider-area.
JS (using JQuery):
Here you set a timer which will call the changeSlide function every 5 seconds. The changeSlide function will take the current position of the slider's scrollbar and animate it accordingly. If it's displaying the last slide, next one will be the first slide (pos=0) and if it's not displaying the last slide, it adds 400 to the position so that it will scroll to the next slide. Basically the sliding animation is simply moving a hidden scrollbar with a timer.
Hopefully that helps!
只需使用 jQuery 旋转出包含图像和关联文本的
即可。使用
$.hide()
和$.show()
以及 Javascript 的时间函数。Just use jQuery to rotate out a
<div>
containing an image and associated text. Use$.hide()
and$.show()
and Javascript's time functions.您可以尝试:
JAVASCRIPT
HTML
You could try:
JAVASCRIPT
HTML