简体   繁体   中英

Javascript scroll into selected category HTML

How to make when i click a category to scroll into the destination/ example = category 1 = it must scroll to selected category projects

    $('.item-filter').on('click', 'a', function(e) {
    e.preventDefault();
    var selector = $(this).data('filter');

    $(".item-filter a").removeClass("active");
    $(this).addClass("active");

    $(".item").fadeTo("slow", 0.1);
     $(selector).fadeTo("slow", 1);

Check the Demo : enter link description here Add below script on category then a page will be scrolled, if you want to scroll a list then you can also do.

JavaScript $("li[class*='-button']") in place you have to select category.

JQUERY

$("li[class*='-button']").click(function () {
    $('html,body').animate({ scrollTop: $(this).offset().top - 3 }, 500);
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM