jQuery isotope:根据 get 变量过滤页面加载

发布于 2024-12-25 12:28:16 字数 226 浏览 1 评论 0原文

我正在使用 jQuery 同位素插件,并且希望在页面加载时仅显示特定组中的项目。目前所有项目都显示:

http://aproposstudio.com/category/work/

例如,在上面的链接上,有没有办法加载显示“壁画”的页面?

谢谢。

I am working with the jQuery isotope plugin and would like to display only items from a particular group when the page loads. Currently all of the items are displaying:

http://aproposstudio.com/category/work/

For example, on the link above, is there a way to load the page with the 'murals' displaying?

thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(4

那支青花 2025-01-01 12:28:16

答案很简单:

$('#container').isotope({ filter: '.your-filter-name' });

在代码中使用这一行。

请参阅此链接:http://isotope.metafizzy.co/docs/filtering.html

The answer is quite easy:

$('#container').isotope({ filter: '.your-filter-name' });

Use this line in your code.

Refere this link: http://isotope.metafizzy.co/docs/filtering.html

内心荒芜 2025-01-01 12:28:16

所以我认为您只想使用简单的 hide() 和 show() 方法

如果您使用应用于 html 元素的类,您可以轻松选择它们并使用以下 jQuery 行隐藏它们。

$(".project").hide()
$(".murals").show()

现在,这将“隐藏”所有项目,只显示壁画。

这有道理吗?

So i think you just want to use the simple hide() and show() methods

If you use the classes applied to your html elements, you can easily select them and hide them with the following jQuery lines.

$(".project").hide()
$(".murals").show()

now, what this will do is 'hide' all of the projects, and show only the murals.

Does that make sense?

忘你却要生生世世 2025-01-01 12:28:16

很简单!

(function ($) {
    $(window).load(function () {

        // settings
        var sortBy = 'date', // SORTING: date / name
            sortAscending = true, // SORTING ORDER: true = Ascending / false = Descending

            theFilter = '.YOUR SORT'; // DEFAULT FILTERING CATEGORY

It's very simple!

(function ($) {
    $(window).load(function () {

        // settings
        var sortBy = 'date', // SORTING: date / name
            sortAscending = true, // SORTING ORDER: true = Ascending / false = Descending

            theFilter = '.YOUR SORT'; // DEFAULT FILTERING CATEGORY
岁月流歌 2025-01-01 12:28:16

我的画廊遇到了同样的问题,我看到了你的帖子。非常感谢你的帮助,这真的让我很开心!

这是我使用的最终代码,这可能对面临类似问题的其他人有所帮助。

首先,我为图库设置了一个默认过滤器值,最初设置为“*”以显示所有项目。单击菜单中的链接时,此默认过滤器会发生变化,如下所示:

<h4 class="menu-item"><a class="hover-underline-animation filter" data-filter=".identite-visuelle" href="/portfolio#identite-visuelle">Identité visuelle</a></h4>

这是图库的过滤器按钮:

<ul id="filters">
    <li><a href="#tout" data-filter="*" class="filterable-gallery__btn custom-btn">Tout</a></li>
    <li><a class="filterable-gallery__btn custom-btn" href="#" id="identite-visuelle" data-filter=".identite-visuelle">Identité visuelle</a></li>
    <li><a class="filterable-gallery__btn custom-btn" href="#" id="illustration" data-filter=".illustration">Illustration</a></li>
    <li><a class="filterable-gallery__btn custom-btn selected" href="#" id="print" data-filter=".print">Print</a></li>
    <li><a class="filterable-gallery__btn custom-btn" href="#" id="webdesign-sites-internet" data-filter=".webdesign-sites-internet">Webdesign/Sites Internet</a></li>
</ul>

然后,对于 JavaScript:

// Default Isotope settings
var lastFilter = '*'; // Default filter
var sortBy = 'date'; // Default sorting method
var sortAscending = true; // Default sorting order

var $container = $('#gallery');
$container.isotope({
    itemSelector: '.gallery-item',
    percentPosition: true,
    masonry: {
        columnWidth: '.gallery-sizer'
    },
    sortBy: sortBy,
    sortAscending: sortAscending,
    filter: lastFilter 
});

var $optionsSets = $('#filters');
var $optionsLinks = $optionsSets.find('a');
    
$optionsLinks.click(function() {
    var $this = $(this);
    if ($this.hasClass('selected')) {
        return false;
    }
        
    var selector = $this.attr('data-filter');

    // Update the lastFilter variable with the new selected filter
    lastFilter = selector;
        
    $container.isotope({
        filter: selector
    });
        
    $optionsSets.find('.selected').removeClass('selected');
    $this.addClass('selected');
        
    return false;
});

// Click event for portfolio menu links
$('.portfolio-nav a').click(function(e) {
    e.preventDefault(); // Prevent default link behavior
        
    // Get the selector from the data-filter attribute of the clicked link
    var selector = $(this).attr('data-filter');
    
    // Update the lastFilter variable with the new selected filter
    lastFilter = selector;

    // Trigger a click on the corresponding filter button in Isotope
    $optionsSets.find('[data-filter="' + selector + '"]').trigger('click');
});

我希望这样帮助任何面临类似问题的人!如果您有任何疑问,请随时与我们联系。

I encountered the same issue with my gallery, and I came across your post.Thank you very much for your help, it really made my day!

Here's the final code I used, which might be helpful for others facing a similar problem.

First, I set a default filter value for the gallery, initially set to "*" to show all items. This default filter changes when clicking on a link in the menu, which looks like this:

<h4 class="menu-item"><a class="hover-underline-animation filter" data-filter=".identite-visuelle" href="/portfolio#identite-visuelle">Identité visuelle</a></h4>

Here are the filter buttons for the gallery:

<ul id="filters">
    <li><a href="#tout" data-filter="*" class="filterable-gallery__btn custom-btn">Tout</a></li>
    <li><a class="filterable-gallery__btn custom-btn" href="#" id="identite-visuelle" data-filter=".identite-visuelle">Identité visuelle</a></li>
    <li><a class="filterable-gallery__btn custom-btn" href="#" id="illustration" data-filter=".illustration">Illustration</a></li>
    <li><a class="filterable-gallery__btn custom-btn selected" href="#" id="print" data-filter=".print">Print</a></li>
    <li><a class="filterable-gallery__btn custom-btn" href="#" id="webdesign-sites-internet" data-filter=".webdesign-sites-internet">Webdesign/Sites Internet</a></li>
</ul>

Then, for the JavaScript:

// Default Isotope settings
var lastFilter = '*'; // Default filter
var sortBy = 'date'; // Default sorting method
var sortAscending = true; // Default sorting order

var $container = $('#gallery');
$container.isotope({
    itemSelector: '.gallery-item',
    percentPosition: true,
    masonry: {
        columnWidth: '.gallery-sizer'
    },
    sortBy: sortBy,
    sortAscending: sortAscending,
    filter: lastFilter 
});

var $optionsSets = $('#filters');
var $optionsLinks = $optionsSets.find('a');
    
$optionsLinks.click(function() {
    var $this = $(this);
    if ($this.hasClass('selected')) {
        return false;
    }
        
    var selector = $this.attr('data-filter');

    // Update the lastFilter variable with the new selected filter
    lastFilter = selector;
        
    $container.isotope({
        filter: selector
    });
        
    $optionsSets.find('.selected').removeClass('selected');
    $this.addClass('selected');
        
    return false;
});

// Click event for portfolio menu links
$('.portfolio-nav a').click(function(e) {
    e.preventDefault(); // Prevent default link behavior
        
    // Get the selector from the data-filter attribute of the clicked link
    var selector = $(this).attr('data-filter');
    
    // Update the lastFilter variable with the new selected filter
    lastFilter = selector;

    // Trigger a click on the corresponding filter button in Isotope
    $optionsSets.find('[data-filter="' + selector + '"]').trigger('click');
});

I hope this helps anyone facing a similar issue! Feel free to reach out if you have any questions.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文