猫头鹰旋转木马2自定义导航
owl carousel 2 custom nav
我正在使用owl carousel 1插件,我正试图将我所有的东西升级到版本2。我有一个带有自定义导航条的滑块:
$(document).ready(function () {
function customPager() {
$.each(this.owl.userItems, function (i) {
var titleData = jQuery(this).find('img').attr('title');
var paginationLinks = jQuery('.owl-controls .owl-pagination .owl-page span');
$(paginationLinks[i]).append(titleData);
});
}
$('.rri-carousel').owlCarousel({
navigation : false, // Show next and prev buttons
slideSpeed : 300,
paginationSpeed : 400,
singleItem : true,
lazyLoad : true,
afterInit : customPager,
afterUpdate : customPager,
transitionStyle : "fade",
autoPlay : true,
stopOnHover : true
});
});
如何将此转换为猫头鹰旋转木马2?我现在有:
$(document).ready(function () {
function customPager() {
$.each(this.owl.userItems, function (i) {
var titleData = jQuery(this).find('img').attr('title');
var paginationLinks = jQuery('.owl-controls .owl-pagination .owl-page span');
$(paginationLinks[i]).append(titleData);
});
}
$('.rri-carousel').owlCarousel({
loop : true,
items : 1,
nav : false,
onInitialized : customPager,
onResized : customPager
});
});
然而,我得到Uncaught TypeError: Cannot read property 'userItems' of undefined
在铬控制台,当我点击它,它显示错误是在this.owl.userItems
上的$.each(this.owl.userItems, function (i) {
。
我假设函数在更新中被删除以更改,但我无法弄清楚这一点,我是javascript的新手。
我不仅得到这个错误,而且没有看到像第一个版本那样的分页。
谢谢,希望有人能给我指出正确的方向。
编辑:我复制了你的javascript,但仍然没有分页。这是我的php输出的html:
function rri_function($type = 'rri_function') {
$args = array(
'post_type' => 'rri_images',
'posts_per_page' => 5
);
$result = '<div class="rri-carousel owl-theme">';
//the loop
$loop = new WP_Query($args);
while ($loop->have_posts()) {
$loop->the_post();
$the_url = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), $type);
$result .= '<div><img src="' . $the_url[0] . '" title="' . get_the_title() . '" data-thumb="' . $the_url[0] . '" alt="' . get_the_title() . '"></div>';
}
$result .= '</div>';
return $result;
}
,下面是打印在页面上的内容:
上一页下一个div>我是新的javascript,但这为我工作。Owl carousel 2有不同的CSS类:。owl-dots .owl-dot而不是。
我也改变了this.owl。userItems到$('.owl-item')选择每个carousel项目(不确定这是否是合适的解决方案)。
$(document).ready(function () {
function customPager() {
$.each($('.owl-item'), function (i) {
var titleData = jQuery(this).find('img').attr('title');
var paginationLinks = jQuery('.owl-dots .owl-dot span');
$(paginationLinks[i]).append(titleData);
});
}
$('.rri-carousel').owlCarousel({
loop : true,
items : 1,
nav : false,
onInitialized : customPager,
});
});
编辑:我已经删除了onResized: customPager参数,因为它在调整浏览器窗口大小时反复添加现有链接后的新链接。然而,我不清楚这个参数的目的是什么。
该错误表明'owl'没有在'this'即customPager函数上定义。实际上,在你的代码中没有任何地方定义名为'owl'的变量。我查了一下owl-carousel 2.0的文档,我猜你需要这样的东西。
var owl = $('.rri-carousel');
和我在文档中没有看到任何名为'userItems'的变量。但是您可以使用jquery访问这些元素。从长远来看,
$(document).ready(function () {
var owl = $('.rri-carousel');
function customPager() {
$.each($(owl).find('.item'), function (i) {
var titleData = jQuery(this).find('img').attr('title');
var paginationLinks = jQuery('.owl-controls .owl-pagination .owl-page span');
$(paginationLinks[i]).append(titleData);
});
}
owl.owlCarousel({
loop : true,
items : 1,
nav : false,
onInitialized : customPager,
onResized : customPager
});
});
我不能完全测试它是否工作,因为我没有你的html来测试它,但我在我的机器上没有任何问题。
- 自定义导航栏切换(从下拉列表到从左侧滑动)
- 使用自定义汉堡包按钮用jQuery触发MDBootstrap侧导航
- 粘性导航-JS Waypoints在浏览器调整大小时出现自定义粘性导航问题
- 一页滚动自定义导航
- 导航到 JavaScript 中带有自定义请求标头的 URL
- 谷歌地图自定义路线到安卓导航
- 角度 UI 固定自定义导航栏
- 花式框v2:自定义按钮导航
- Jquery 在 Firefox 中的自定义对象参数(动态导航加载动态内容)
- 自定义jQuery/JavaScript滑块在我点击箭头/导航时出错
- 引导自定义 CSS 导航栏
- 具有自定义导航栏的 UIAutomation
- 如何使此自定义双导航同时响应和修复
- 将自定义屏幕导航编码为 Lightswitch HTML
- 在自定义帖子类型滑块上添加导航链接
- 自定义CSS导航下拉列表
- YUI旋转木马自定义导航
- 如何在提供自定义HTTP标头的同时使用javascript导航到网站
- 使用自定义对话框提示用户尝试使用未保存的数据进行导航
- jquery自定义控制的滚动导航