我使用 SwipeView ( http://cubiq.org/swipeview ) 正确实现了触摸幻灯片,但我需要超越并允许每个图像幻灯片链接到另一个页面。
你做过吗?
请告诉我如何实现这一目标!我在项目站点中看到几个月前有人问过同样的问题而没有答案。这就是我在这里的原因。
这是您所知道的代码:
<div id="wrapper"></div>
<script type="text/javascript">
document.addEventListener('touchmove', function (e) { e.preventDefault(); }, false);
var gallery,
el,
i,
page,
dots = document.querySelectorAll('#nav li'),
slides = [
{
img: 'images/1.png',
width: 270,
height: 365
link: 'www.google.com,
},
{
img: 'images/2.png',
width: 270,
height: 365,
},
{
];
gallery = new SwipeView('#wrapper', { numberOfPages: slides.length });
// Load initial data
for (i=0; i<3; i++) {
page = i==0 ? slides.length-1 : i-1;
el = document.createElement('img');
el.className = 'loading';
el.src = slides[page].img;
el.width = slides[page].width;
el.height = slides[page].height;
el.onload = function () { this.className = ''; }
gallery.masterPages[i].appendChild(el);
el = document.createElement('span');
el.innerHTML = slides[page].desc;
gallery.masterPages[i].appendChild(el)
}
gallery.onFlip(function () {
var el,
upcoming,
i;
for (i=0; i<3; i++) {
upcoming = gallery.masterPages[i].dataset.upcomingPageIndex;
if (upcoming != gallery.masterPages[i].dataset.pageIndex) {
el = gallery.masterPages[i].querySelector('img');
el.className = 'loading';
el.src = slides[upcoming].img;
el.width = slides[upcoming].width;
el.height = slides[upcoming].height;
el = gallery.masterPages[i].querySelector('span');
el.innerHTML = slides[upcoming].desc;
}
}
document.querySelector('#nav .selected').className = '';
dots[gallery.pageIndex+1].className = 'selected';
});
gallery.onMoveOut(function () {
gallery.masterPages[gallery.currentMasterPage].className = gallery.masterPages[gallery.currentMasterPage].className.replace(/(^|\s)swipeview-active(\s|$)/, '');
});
gallery.onMoveIn(function () {
var className = gallery.masterPages[gallery.currentMasterPage].className;
/(^|\s)swipeview-active(\s|$)/.test(className) || (gallery.masterPages[gallery.currentMasterPage].className = !className ? 'swipeview-active' : className + ' swipeview-active');
});
</script>
非常感谢!
-马塞洛