【发布时间】:2013-05-15 21:57:37
【问题描述】:
我知道这是一个很受欢迎的问题,但我在使用 Isotope 网站上的教程来开发我当前的同位素以使用 BBQ hash history 时遇到了一些困难。
我实际上是在尝试将 BBQ 哈希历史添加到我当前的设置中,以便我可以直接链接到过滤后的内容。
到目前为止,这是我的 jQuery 代码,运行良好。
jQuery(function () {
var $container = jQuery('.wwd-content-container');
$container.imagesLoaded(function () {
$container.isotope({
itemSelector: '.each-wwd-content',
filter: '.corporate'
});
});
jQuery('.wwd-filters a').click(function () {
jQuery('a.active-filter').removeClass('active-filter');
jQuery(this).addClass('active-filter');
var selector = $(this).attr('data-filter');
$container.isotope({
filter: selector
});
return false;
});
});
我已将过滤器导航更改为:
<li><a href="#" data-filter=".<?php echo esc_attr( $page_class ) ?>"><?php the_title(); ?></a></li>
到
<li><a href="#filter=.<?php echo esc_attr( $page_class ) ?>"><?php the_title(); ?></a></li>
我使用的是 Wordpress,因此使用了 $page_class 变量等——但不要在这上面花太多时间。
谢谢,任何帮助将不胜感激。 回复
更新
这就是我目前所拥有的......
jQuery(function () {
var $container = jQuery('.wwd-content-container');
$container.imagesLoaded(function () {
$container.isotope({
itemSelector: '.each-wwd-content',
filter: '.corporate'
});
});
jQuery('.wwd-filters a').click(function () {
jQuery('a.active-filter').removeClass('active-filter');
jQuery(this).addClass('active-filter');
var selector = $(this).attr('data-filter');
$container.isotope({
filter: selector
});
return false;
});
jQuery('.wwd-filters a').click(function(){
// get href attr, remove leading #
var href = jQuery(this).attr('href').replace( /^#/, '' ),
// convert href into object
// i.e. 'filter=.inner-transition' -> { filter: '.inner-transition' }
option = $.deparam( href, true );
// set hash, triggers hashchange on window
$.bbq.pushState( option );
return false;
});
jQuery(window).bind( 'hashchange', function( event ){
// get options object from hash
var hashOptions = $.deparam.fragment();
// apply options from hash
$container.isotope( hashOptions );
})
// trigger hashchange to capture any hash data on init
.trigger('hashchange');
});
【问题讨论】:
标签: javascript jquery jquery-isotope jquery-bbq