jquery - 尝试构建一个 jQuery 滑块
问题描述
我试图在 WordPress 中构建一个动态滑块,使用 jquery 加载动态画廊图像的 php 数组,我事先不知道滑块中有多少图像。
这是我到目前为止写的代码。
<script>
$(document).ready(function() {
//Slider
$('.wp-post-image img').addClass('Slide'); //Add class to the gallery images
$('.wp-post-image img').click(function() {
var MyImageArray = <? wc_get_template('single-product/product-thumbnails.php');?>;
var focusImg = 1;
var imageHold = MyImageArray[focusImg];
focusImg++;
if(focusImg > 4) {//to be honest not sure about this number
focusImg = 0;
}
});
$('.wp-post-image img').attr('src','imageHold');
$('.Slide').css('position','absolute');
$('#Slider_Arrow_Left').click(function() {
$('.Slide').animate({'right':'+=500','easing':'swing'});
$('.Slide').css('z-index','10000');
});
$('#Slider_Arrow_Right').click(function() {
$('.Slide').animate({'left':'+=500','easing':'swing'});
$('.Slide').css('z-index','10000');
});
}); //End jquery
</script>
如您所见,我试图使用左右箭头元素来滑动加载的图像。
我究竟做错了什么?
解决方案
我个人建议你试试这个https://owlcarousel2.github.io/OwlCarousel2/demos/demos.html
它有很多属性,您可以通过这些属性来满足您的要求。我希望这会对你有所帮助
推荐阅读
- drag-and-drop - Genero 4gl 中有没有办法创建拖放以插入文件?
- android - 如何使用 Retrofit 2 处理错误响应
- ios - React Native / iOS:从推送通知打开应用程序后,应用程序在启动屏幕上挂起
- php - 获取标签中没有的XML内容,并通过前面的标签将它们分成数组
- amazon-web-services - create autoscaling group from launch configuration 错误:t2.micro 实例类型不支持指定 CpuOptions
- c# - 通过elasticSearch计算子数组中不同值的计数?
- python - Selenium 网络抓取应用程序 - 如何从 302 重定向中获取最终下载 URL
- javascript - Carousel Bootstrap 5:从 JQuery 到 Javascript
- android - 仅使用本机上下文视图的混合应用程序自动化
- c# - 无法打开附件 - Xamarin.Forms App