jquery Scroll to class name

后端 未结 4 1363
慢半拍i
慢半拍i 2020-12-16 13:33

I have the Html code like below,

4条回答
  •  北海茫月
    2020-12-16 13:56

    You are not targeting a DOM object, you are targeting a string.

    scrollTo = $(this).find('.saveIcon').attr('data-unique', 456); -> this is wrong
    

    So, while you are trying to target an element, you are actually setting the 'data-unique' to the '.saveIcon' element.

    Try this:

    scrollTo = $('.saveIcon');
    

    Working code:

    var $container = $("html,body");
    var $scrollTo = $('.saveIcon');
    
    $container.animate({scrollTop: $scrollTo.offset().top - $container.offset().top + $container.scrollTop(), scrollLeft: 0},300); 
    

提交回复
热议问题