jQuery Cycle 插件帮助
我正在尝试使用 jQuery Cycle 插件构建一个滑动旋转器,但是在我需要的自定义显示方面遇到了一些问题...基本上我有幻灯片,并且在每张幻灯片的顶部都有一个带有文本的文本框。我只想幻灯片滑动,但我希望文本淡出,然后在新幻灯片进入时淡入。
这是我的 HTML:
<div id="home-slider">
<div class="slide">
<img src="image.jpg" width="200" height="200" />
<div class="text-box">
<p>Some text here</p>
</div>
</div>
<div class="slide">
<img src="image.jpg" width="200" height="200" />
<div class="textblock">
<p>Some text here</p>
</div>
</div>
</div>
这是 JS:
function onBefore() {
jQuery("#home-slider .slide .textblock").hide();
}
function onAfter() {
jQuery("#home-slider .slide .textblock").fadeIn('fast');
}
jQuery("#home-slider").cycle({
speed: 500,
timeout: 3000,
after: onAfter,
before: onBefore
});
所以幻灯片工作正常,但当我想要时文本会随之滑动他们只是淡入/淡出。
有什么想法吗?
I am trying to build a sliding rotator with jQuery Cycle plugin but am having some trouble with a custom display that I need...Basically I have the slides and on top of each slide there is a textbox with text. I just want the slides to slide but I want the text to fadeout and then in when the new slide comes in.
Here is my HTML:
<div id="home-slider">
<div class="slide">
<img src="image.jpg" width="200" height="200" />
<div class="text-box">
<p>Some text here</p>
</div>
</div>
<div class="slide">
<img src="image.jpg" width="200" height="200" />
<div class="textblock">
<p>Some text here</p>
</div>
</div>
</div>
Here is the JS:
function onBefore() {
jQuery("#home-slider .slide .textblock").hide();
}
function onAfter() {
jQuery("#home-slider .slide .textblock").fadeIn('fast');
}
jQuery("#home-slider").cycle({
speed: 500,
timeout: 3000,
after: onAfter,
before: onBefore
});
So the slides are working fine but the text are sliding with it when I want them to just fade in/out instead.
Any idea?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
对于滑动,您必须将
fx
属性设置为“scrollHorz
”或scorllVert
。看看这个工作演示。另外,您的班级名称中有一些拼写错误。演示
For sliding you have to set the
fx
property either to 'scrollHorz
orscorllVert
. Take a look at this working demo. Aslo you have some typo's in your class names.Demo
您在 jquery 调用中缺少“#”,并且在 html 的某一部分中缺少其调用的文本框:
You are missing the "#" in your jquery calls and its called text-box in one section of your html:
我相信发生的情况是幻灯片 div 已经隐藏,因此 onbefore 没有任何效果,因为它之后显示。
解决这个问题的一种方法是使用文本缩进将其从屏幕上移开,然后将其隐藏,正确地重新定位文本,然后淡入。
另一种选择是在文本上方放置一个 div 以隐藏它,然后隐藏下面的内容文本 onafter 并删除 div 并淡入。
第三个选项是仅选择循环功能中的图像。 jQuery("#home-slider img").cycle 或者如果这不起作用,则将它们放在单独的 div 中进行循环。
I believe what is happening is that the slide div is already hidden, so onbefore doesn't have any effect as it is shown afterwards.
One way around this could be to use text-indent to have it off the screen and then hide it onafter, reposition the text correctly and then fade in.
Another option is to have a div overtop the text to hide it and then hide the below text onafter and remove the div and fade in.
A third option is to choose only the images in the cycle function. jQuery("#home-slider img").cycle or if that doesn't work, then have them in a separate div to cycle through.