Blogger Information
Blog 56
fans 7
comment 11
visits 223151
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
js点击滚动到指定位置
樂成的开发笔记
Original
4239 people have browsed it

js点击滚动到指定位置,比如左边分类点击右边列表滚动,直接用a标签锚点滚动的位置不够灵活,这方法还是不错的

$(document).ready(function(){
            $(".category-a").click(function(){
              $(".category-a").removeClass("active");
              $(this).addClass("active");
              var cid = $(this).attr("data-cid");  //将要滚到的元素ID
              var scroll_offset = $("#" + cid).offset(); //滚到的元素ID
              var scroll=scroll_offset.top-150;
            $(".goodslist,html").animate({ //$("body,html") body内滚动或者自己写的div但需要overflow auto
                scrollTop:scroll //让body的scrollTop等于pos的top,就实现了滚动 
                },500); 
            });
        });


Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post