2012-03-17 92 views
0

我已经对一个大菜单进行了分页 - 用户每次在面板中看到12个项目。jQuery - 记住页面变化的菜单位置

其右侧的菜单,在这里:http://bartlettstudio.com/

你可以看到我的问题,当你点击更多的项目,然后从第二面板的链接。

就拿这一个例子:http://bartlettstudio.com/projects/dog-named-lucky/

当你在该网页上,工具栏菜单恢复到第一面板,你有没有办法告诉你什么菜单项。您需要点击更多项目才能看到“Dog Luckyd”菜单项。

问题

谁能帮助我弄清楚如何处理这个问题?其他人提到使用jQuery hashchange,但这已被证明是我的头。任何人都可以想办法解决这个问题吗?

有了太多的感谢

特里

+0

更新问题:jQuery haschange可以用于这样的事情吗?点击更多项目时,我不会更改网址。 Cookie是解决此问题的唯一方法吗? – saltcod 2012-03-17 15:09:51

+0

您可以使用cookies,但我不确定这是否会增加复杂性。这是如何:http://www.w3schools.com/js/js_cookies.asp – 2012-03-17 15:45:51

回答

1

更多的项目链接可以更改为具有A HREF它可以说:

<a href="#more-1" class="next">More Projects</a> 

这时旁边的onClick你可以做这样的事情在jQuery的:

jQuery(function ($) { 

    if(window.location.hash) { 
     // onLoad hash was detected 
     console.log('onLoad hash detected // do something to position menu'); 

     // window.location.hash starts with a # following with the string behind it 
     // window.location.hash.slice(1) gets the string only 
    } 


    // This isn't needed but quessing you already have an onClick set up for this element... 
    $('a.next').click(function (e) { 
     /* 
     Don't do e.preventDefault()! The browser will add the href hash value itself if you only specified the hash! 
     If you want to preventit you will have to set the hash yourself like this: 

     window.location.hash = 'more-1'; 
     */ 

     // do stuff, possibly with the href value since you have it anyway 


     // I reccommend that you change the value of the href to specify the next hash value change 
     $(this).attr('href', '#more-2'); 
    }); 

}); 
+0

作为一个简要说明;我会隐藏更多的项目和反向链接,如果你不能回去或没有更多的项目加载.... – sg3s 2012-03-17 15:46:40

+0

所以,这基本上增加了一个散列让我用jQuery hashchange插件?这是这个想法吗? – saltcod 2012-03-17 15:52:26

+0

你不需要插件。只有两次你想使用散列,你可以捕捉不同的;一旦在页面加载之后,以及用户点击锚点以查看更多项目或想要返回时......并且您已经对click事件做了一些操作,所以您只需添加一小段代码即可识别在负载上显示正确的页面的项目.... – sg3s 2012-03-17 15:58:07