带有锚点和缩略图的 jQuery Cycle

发布于 2024-10-05 14:27:58 字数 1095 浏览 1 评论 0原文

我正在使用 jQuery Cycle 插件构建一个幻灯片,其中主图像包含在锚点中,并且还具有缩略图导航。我基本上从 jQuery Cycle 的 演示页面 获得了相同的代码。一旦我将图像包装在链接中,缩略图就损坏了。我尝试删除 $('#slideshow img).attr('src') 的“slide.src”,但仍然显示为未定义。

$('#slideshow').before('<ul id="slideshow-nav">').cycle({
 fx: 'fade',
 speed: 'slow',
 timeout: 0,
 pager: '#slideshow-nav',

 pagerAnchorBuilder: function(idx, slide){
 return '<li class="thumbnail"><a href="#"><img class="rounded" src="' + slide.src + '" width="137" height="129" /></a><span class="highlight"></span><span class="gloss"></span></li>';
 }
});

我的html是这样的。

<div id="slideshow">
 <a href="#"><img src="images/gyro.jpg"  alt="Gyro"></a>
 <a href="#"><img src="images/gyro.jpg"  alt="Gyro"></a>
 <a href="#"><img src="images/gyro.jpg"  alt="Gyro"></a>
 <a href="#"><img src="images/gyro.jpg"  alt="Gyro"></a>
 </div>

I'm using the jQuery Cycle plugin to build a slideshow that the main image is wrapped in an anchor and also has the thumbnail navigation. I basically have the same code from the demo page of jQuery Cycle. Once I wrapped the images in a link the thumbnails broke. I have tried dropping the "slide.src" for $('#slideshow img).attr('src') but that still comes back as undefined.

$('#slideshow').before('<ul id="slideshow-nav">').cycle({
 fx: 'fade',
 speed: 'slow',
 timeout: 0,
 pager: '#slideshow-nav',

 pagerAnchorBuilder: function(idx, slide){
 return '<li class="thumbnail"><a href="#"><img class="rounded" src="' + slide.src + '" width="137" height="129" /></a><span class="highlight"></span><span class="gloss"></span></li>';
 }
});

And my html is this.

<div id="slideshow">
 <a href="#"><img src="images/gyro.jpg"  alt="Gyro"></a>
 <a href="#"><img src="images/gyro.jpg"  alt="Gyro"></a>
 <a href="#"><img src="images/gyro.jpg"  alt="Gyro"></a>
 <a href="#"><img src="images/gyro.jpg"  alt="Gyro"></a>
 </div>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

冰葑 2024-10-12 14:27:59

您需要向 $.before() 提供有效的 HTML 片段。目前您没有结束 标记。最干净的方法是自动关闭标签:

$('#slideshow').before('<ul id="slideshow-nav" />').cycle({ ...

如果您在 Webkit 浏览器中使用 Firebug 或开发人员工具,您始终可以通过编写 console.log($("# Slideshow-nav")); 或回调函数中的 console.log($(slide));

You need to supply a valid HTML fragment to $.before(). At the moment you have no closing </ul> tag. The cleanest way to do this is to self-close the tag:

$('#slideshow').before('<ul id="slideshow-nav" />').cycle({ ...

If you're using Firebug or the developer tools in a Webkit browser you can always see what elements jQuery is finding by writing console.log($("#slideshow-nav")); or console.log($(slide)); in your callback function.

眼趣 2024-10-12 14:27:59

没关系,我在脚本的其他地方发现了一个错误,该错误正在修改缩略图,该错误由于某种原因破坏了图像。

Never mind I found an error elsewhere in my script that is modifying the thumbnails that was for some reason breaking the images.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文