如何使用 jQuery 工具进行深度链接?可滚动

发布于 2024-12-22 03:00:07 字数 1684 浏览 4 评论 0原文

我使用 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 技术交流群。

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

发布评论

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

评论(1

谎言月老 2024-12-29 03:00:07

回到我之前的回答,我发现了一些巧妙的东西:

unescape(self.document.location.hash.substring(1));

所以有了这个你可以做类似的事情:

//onload
var hash = self.document.location.hash.substring(1) ;
if(hash != ""){
  //Run your scrollto code with the hash var
}

Coming back on my previous answer, I found something neat:

unescape(self.document.location.hash.substring(1));

So with this you could do something like:

//onload
var hash = self.document.location.hash.substring(1) ;
if(hash != ""){
  //Run your scrollto code with the hash var
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文