我如何添加导航箭头上的“JQuery照片滑块与半透明标题”
How can I add navigation arrows on the “JQuery Photo Slider with Semi Transparent Caption”?
我正在使用来自queness.com (http://www.queness.com/resources/html/slideshow/jquery-slideshow.html)的"JQuery照片滑块与半透明标题",我喜欢它。
唯一缺少的是导航按钮。我已经修改了原来的HTML并添加了导航按钮,但不知道如何实例化/调用导航:
<div style="opacity: 1; visibility: visible; width: 550px; height: 350px;">
<div id="slider-container">
<ul class="slideshow">
@foreach ($images as $image)
<li class="show"><a href="/link/{{ $image->id }}" target="_blank"><img src="{{ $image->image_src }}" width="550" height="350" title="Title" alt="Desc"/></a></li>
@endforeach
</ul>
</div>
<div id="navigation">
<img style="opacity: 0;" id="prev" class="prev-button" src="prev.png" alt="Previous">
<img style="opacity: 0;" id="next" class="next-button" src="next.png" alt="Next">
<img style="opacity: 0; margin-left: -17px; display: none;" id="play" class="play-button" src="play.png" alt="Play">
<img style="opacity: 0; margin-left: -17px; display: none;" id="pause" class="pause-button" src="pause.png" alt="Pause">
</div>
</div>
理想情况下,我需要导航显示在悬停,就像在这个页面:http://airmaster.co.ke/
那么,您需要做的是为导航按钮设置几个单击处理程序。我不确定你是否也想从例子中实现播放/暂停按钮功能,因为它没有在你的问题中提到。
因此,首先,由于您的下一个和上一个导航按钮实际上是图像,并且您已经为它们提供了id,因此我们可以使用jQuery设置点击处理程序,如下所示:$('#prev').click(function(){
// Handle click here
})
$('#next').click(function(){
// Handle click here
})
现在已经设置了单击处理程序,我们需要实现实际的导航。根据这个链接(http://www.queness.com/post/152/simple-jquery-image-slide-show-with-semi-transparent-caption),导航实现如下:
//if no li has the show class, grab the first image
var current = ($('ul.slideshow li.show')? $('ul.slideshow li.show') : $('ul.slideshow li:first'));
$('#prev').click(function(){
//Get previous image, if it reached the beginning of the slideshow, rotate it back to the last image
var prev = (current.prev().length) ? current.prev() : $('ul.slideshow li:last');
//Set the fade in effect for the next image, show class has higher z-index
prev.css({opacity: 0.0})
.addClass('show')
.animate({opacity: 1.0}, 1000);
//Hide the current image
current.animate({opacity: 0.0}, 1000)
.removeClass('show');
});
$('#next').click(function(){
//Get next image, if it reached the end of the slideshow, rotate it back to the first image
var next = (current.next().length) ? current.next() : $('ul.slideshow li:first');
//Set the fade in effect for the next image, show class has higher z-index
next.css({opacity: 0.0})
.addClass('show')
.animate({opacity: 1.0}, 1000);
//Hide the current image
current.animate({opacity: 0.0}, 1000)
.removeClass('show');
});
同样,你应该从这个列表项中删除类"show":
<li class="show"><a href="/link/{{ $image->id }}" target="_blank"><img src="{{ $image->image_src }}" width="550" height="350" title="Title" alt="Desc"/></a></li>
所以应该是:
<li><a href="/link/{{ $image->id }}" target="_blank"><img src="{{ $image->image_src }}" width="550" height="350" title="Title" alt="Desc"/></a></li>
因为这个循环实际上给了每个li一个show类,这会破坏你的代码。
从理论上讲,应该可以使代码正常工作。但是,由于您没有提供足够的代码或JSFiddle,我无法为您制作一个工作示例。
参考下面的链接(上面提到的),以了解更多关于如何在代码中实现附带内容的信息:
http://www.queness.com/post/152/simple-jquery-image-slide-show-with-semi-transparent-caption编辑
我还忘了添加如何在悬停时显示导航按钮。这是你应该添加的内容:
$('#navigation').hover(function(){
// Code for when mouse enters
// Animate opacity to 1 (fully visible) in 200 ms
$('#next').animate({opacity: 1.0}, 200);
$('#prev').animate({opacity: 1.0}, 200)
},function(){
// Code for when mouse leaves
// Animate opacity to 0 (invisible) in 200 ms
$('#next').animate({opacity: 0.0}, 200);
$('#prev').animate({opacity: 0.0}, 200)
});
我从来没有使用过这个滑块,我也不太了解JQuery,但我确实想尝试帮助。你考虑过滑滑吗?它非常简单,只有1页(不多不少)的教程,而且效果很好。你可以在这里找到:http://kenwheeler.github.io/slick/。它做你需要的,而且是免费的。如果您想保持当前的滑块,恐怕我帮不了您。好运!
- 在照片查看器(Javascript和jQuery)中异步加载图像时可能出现错误
- 照片拼贴与jquery和html5
- 类似facebook的照片查看器jQuery FBPhotoBox
- 如何将不区分大小写添加到照片库搜索框jquery
- 背景图像旋转器.php + jQuery每4秒显示一次随机照片
- 如何使用裁剪和上传照片 jquery 插件与 php.
- jQuery 重新排列/交换 img src 会导致照片重新加载出现故障
- Jquery 动画第二张照片未显示
- jQuery照片网格没有达到预期效果
- 使用ASP.NET MVC站点中的jQuery对话框上载照片
- 我只想让我的应用程序获取一个访问令牌,用javascript/jquery读取公共照片库
- jQuery插件类似于《今日美国》's的文章照片
- 垂直间隙出现-jQuery砖石-(无缝照片网格)
- 调整窗口大小时,jQuery Masonry布局正在崩溃——流畅的无缝照片网格
- 照片库(幻灯片)与jQuery
- jQuery照片库错误,如果鼠标移动很快
- 将Javascript手风琴式菜单效果与jQuery可过滤照片库相结合
- 在父容器上使用克隆的Jquery拖放照片编辑器
- 修改Jquery以展开不同位置的每张照片
- 在弹出窗口Jquery(灯箱)中打开照片