2012-05-08 11 views
0

フィルタリング可能なポートフォリオを使用しています。私はポートフォリオをフィルタリングするためのリンクに少し問題があります。フィルタリング可能なポートフォリオハッシュタグ

ボタンをクリックすると、ポートフォリオが正しくフィルタリングされますが、その後、xy.com/#myfilterのようなサイトに自動的に接続され、開こうとします。

おそらくこれを無効にする方法がありますか?

LINKのSAMPLE:

<a href="#design" rel="design">Design</a> 

JS-FILEは以下の通りです:

(function($) { 
    $.fn.filterable = function(settings) { 
    settings = $.extend({ 
     useHash   : true, 
     animationSpeed : 500, 
     show    : { width: 'show', opacity: 'show' }, 
     hide    : { width: 'hide', opacity: 'hide' }, 
     useTags   : true, 
     tagSelector  : '#portfolio-filter a', 
     selectedTagClass : 'current', 
     allTag   : 'all' 
    }, settings); 

    return $(this).each(function(){ 

     /* FILTER: select a tag and filter */ 
     $(this).bind("filter", function(e, tagToShow){ 
     if(settings.useTags){ 
      $(settings.tagSelector) 
      .removeClass(settings.selectedTagClass); 
      $(settings.tagSelector + '[href=' + tagToShow + ']') 
      .addClass(settings.selectedTagClass); 
     } 

     $(this).trigger("filterportfolio", [ tagToShow.substr(1) ]); 
     }); 

     /* FILTERPORTFOLIO: pass in a class to show, all others will be hidden */ 
     $(this).bind("filterportfolio", function(e, classToShow){ 
     if(classToShow == settings.allTag){ 
      $(this).trigger("show"); 
     }else{ 
      $(this).trigger("show", [ '.' + classToShow ]); 
      $(this).trigger("hide", [ ':not(.' + classToShow + ')' ]); 
     } 

     if(settings.useHash){ 
      location.hash = '#' + classToShow; 
     } 
     }); 

     /* SHOW: show a single class*/ 
     $(this).bind("show", function(e, selectorToShow){ 
     $(this) 
      .children(selectorToShow) 
      .animate(settings.show, settings.animationSpeed); 
     }); 

     /* SHOW: hide a single class*/ 
     $(this).bind("hide", function(e, selectorToHide){ 
     $(this) 
      .children(selectorToHide) 
      .animate(settings.hide, settings.animationSpeed); 
     }); 

     /* ============ Check URL Hash ====================*/ 
     if(settings.useHash){ 
     if(location.hash != '') { 
      $(this).trigger("filter", [ location.hash ]); 
     }else{ 
      $(this).trigger("filter", [ '#' + settings.allTag ]); 
     } 

     /* ============ Setup Tags ====================*/ 
     if(settings.useTags){ 
      $(settings.tagSelector).click(function(){ 
      $('#portfolio-list').trigger("filter", [ $(this).attr('href') ]); 
      $(settings.tagSelector).removeClass('current'); 
      $(this).addClass('current'); 
      }); 
     } 
     }); 
    } 
})(jQuery); 


$(document).ready(function(){ 

    $('#portfolio-list').filterable(); 

}); 

それはまた、私は私の検索友好のURLに問題があること、だろうか? ご協力いただきありがとうございます。

よろしくお願いいたします。

$(settings.tagSelector).click(function(){ 
    $('#portfolio-list').trigger("filter", [ $(this).attr('href') ]); 

    $(settings.tagSelector).removeClass('current'); 
    $(this).addClass('current'); 
}); 

変更し、それに:

$(settings.tagSelector).click(function(event){ 
    $('#portfolio-list').trigger("filter", [ $(this).attr('href') ]); 

    $(settings.tagSelector).removeClass('current'); 
    $(this).addClass('current'); 

    // push the hash into the url 
    location.hash = $(this).attr('href'); 

    // stop the regular href 
    event.preventDefault(); 
}); 

これはあなたのことができますあなたの現在のクリック機能で

+0

'a'にはそれに関連するスクリプトはありません。 – Zuul

答えて

1

あなたはクリックイベントにいくつかの調整をする必要がありますハッシュ値をURLに配置するが、ブラウザが実際にPAをリロードするのを防ぐユーザーがリンクをクリックするとそのハッシュを持つge!


それについて続きを読む:

event.preventDefault() | location.hash

+0

それは素晴らしいです。あなたの有益な仕事をありがとう! – designsforweb

+0

これで問題が解決した場合は、このトピックを閉じる答えをチェックしてください。 PS:私は助けることができてうれしい! – Zuul

関連する問題