如何使用 jQuery 工具进行深度链接?可滚动
我使用 jQuery Tools 的 Scrollable 作为浏览整个单页网站的方法。
导航看起来像这样:
<div id="mainNavContainer">
<nav>
<a id="logo" href="#home" title="Hughes Opticians, Delmar, NY"></a>
<a href="#who-we-are" title="Who We Are">Who We Are</a>
<a href="#eye-exams" title="Eye Exams">Eye Exams</a>
<a href="#gallery" title="Gallery">Gallery</a>
<a href="#eyewear" title="Eyewear">Eyewear</a>
<a href="#contact-lenses" title="Contact Lenses">Contact Lenses</a>
<a href="#contact" title="Contact">Contact</a>
</nav>
</div>
触发它的 jQuery 看起来像这样:
$("#homeScrollable").scrollable({circular:true, next:'.mainNext', prev:'.mainPrev'}).navigator({navi:'#mainNavContainer nav'});
因此导航水平移动到正确的页面,但哈希不会转到 URL,也无法链接到幻灯片。
基本上,我如何既可以深度链接,又可以使用导航作为插件的导航器目标?
为了响应下面的回复,
我尝试了以下测试:
var hash = self.document.location.hash.substring(1) ;
if(hash == "home"){
console.log('Home page')
}
if(hash == "who-we-are"){
console.log('Who we are page')
}
if(hash == "eye-exams"){
console.log('Eye Exams page')
}
if(hash == "gallery"){
console.log('Gallery page')
}
if(hash == "eyewear"){
console.log('Eyewear page')
}
if(hash == "contact-lenses"){
console.log('Contact Lenses page')
}
if(hash == "contact"){
console.log('Contact page')
}
控制台将每个 console.log 消息回显两次。它不应该只是回显我的 URL 当前的哈希标签吗?
I am using jQuery Tools' Scrollable as the means to navigate through a whole single-page site.
Navigation looks like this:
<div id="mainNavContainer">
<nav>
<a id="logo" href="#home" title="Hughes Opticians, Delmar, NY"></a>
<a href="#who-we-are" title="Who We Are">Who We Are</a>
<a href="#eye-exams" title="Eye Exams">Eye Exams</a>
<a href="#gallery" title="Gallery">Gallery</a>
<a href="#eyewear" title="Eyewear">Eyewear</a>
<a href="#contact-lenses" title="Contact Lenses">Contact Lenses</a>
<a href="#contact" title="Contact">Contact</a>
</nav>
</div>
jQuery to fire it looks like this:
$("#homeScrollable").scrollable({circular:true, next:'.mainNext', prev:'.mainPrev'}).navigator({navi:'#mainNavContainer nav'});
So the navigation moves horizontally to the correct page, but the hash doesn't go to the URL, nor can I link to a slide.
Basically, how can I both deeplink, but also use the nav as the plugin's navigator target?
In response to the reply below,
I tried this to test:
var hash = self.document.location.hash.substring(1) ;
if(hash == "home"){
console.log('Home page')
}
if(hash == "who-we-are"){
console.log('Who we are page')
}
if(hash == "eye-exams"){
console.log('Eye Exams page')
}
if(hash == "gallery"){
console.log('Gallery page')
}
if(hash == "eyewear"){
console.log('Eyewear page')
}
if(hash == "contact-lenses"){
console.log('Contact Lenses page')
}
if(hash == "contact"){
console.log('Contact page')
}
Console echoes each console.log message twice. Should it not just echo my URL's current hash tag?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
回到我之前的回答,我发现了一些巧妙的东西:
所以有了这个你可以做类似的事情:
Coming back on my previous answer, I found something neat:
So with this you could do something like: