【问题标题】:Prefilter Quicksand Page - jQuery预过滤流沙页面 - jQuery
【发布时间】:2012-09-24 18:59:24
【问题描述】:

有没有办法可以预过滤此页面以仅显示“应用程序”。

例如,如果我访问http://razorjack.net/quicksand/demos/one-set-clone.html#app,它只会显示“应用程序”。这可能吗?

谷歌搜索一些人说这会有所帮助:

if(window.location.hash) {
                // run code here to filter the quicksand set
                var $filteredData = $data.find('li[data-type=' + window.location.hash + ']');
                $applications.quicksand($filteredData, {
                    duration: 800
                });
            }

但我不知道在哪里使用它。

非常感谢您的帮助 - 真的卡住了。

【问题讨论】:

  • 如果您试图检测页面加载时的哈希值,只需将此代码放在$(document).ready(function(){ 中,并以该语句的else 为条件来执行@987654325 @。这就是你所需要的。
  • 感谢您的回复 - 和酷的用户名 ;-) 所以,我基本上是在查看是否存在哈希,如果存在,则只显示具有该类名称的条目。你能帮忙吗?

标签: javascript jquery html filter


【解决方案1】:
$(document).ready(function(){
   //on page load, we check to see if a hash value exists.
   if(window.location.hash) {
       // run code here to filter the quicksand set
       var $filteredData = $data.find('li[data-type=' + window.location.hash + ']');
       $applications.quicksand($filteredData, {
           duration: 800
       });
   }else{
       // the page does not have a hash value. deliver normal content.
       $applications.quicksand('Your Normal Data Here', {
           duration: 800
       });
   }
});

此代码仅在页面准备好后运行。它检查哈希值是否存在。如果是这样,它将数据过滤到具有data type equal to the hash valueli 元素。然后它准备流沙以相应地过滤数据。如果不存在哈希值,我们会正常加载流沙。我不知道您对选择器做了什么,所以只需将 'Your Normal Data Here' 替换为您使用的任何数据过滤器即可。

应该注意的是,根据示例,他们希望您拥有一个<li> 结构,如下所示 ->

<li data-type="data1"> //stuff </li>

data1 是用于过滤目的的预期哈希值。

【讨论】:

  • 非常感谢 - 现在将快速尝试一下 - 稍后再回来 :)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多