淘宝首页返回顶部效果怎么做到的
重写window.onscroll()事件,先将返回顶部div设置为position:fixed;right:10px;bottom:10px;display:none,一旦event.scrollTop>100(100可以设置为你想要的值)就display:block(fadeIn()),否则display:none(fadeOut())。还要设置返回顶部div点击事件,onclick(function(){$('body,html').animate({scrollTop:0},1000);}),这个什么意思不用我多说吧,既然搞Jquery,动画还是应该晓得。
<style type="css/text"> #gotop{position:fixed;right:10px;bottom:10px;display:none}</style><div id="gotop"></div><script type="javascript/text"> $(function(){ $(window).scroll(function(){ if($(window).scrollTop > 100){ $("#gotop").fadeIn(1000);//一秒渐入动画 }else{ $("#gotop").fadeOut(1000);//一秒渐隐动画 } }); $("#gotop").click(function(){ $('body,html').animate({scrollTop:0},1000); }); });</script>htmlcss返回顶部按钮位置怎么固定
可以使用相当于浏览器定位。css样式中写入: {position: fixed; right: 20px; bottom: 100px; }相当于浏览器右边20px,浏览器底部100px的距离的定位。
fixed总是以body为定位时的对象,总是根据浏览器的窗口来进行元素的定位,通过"left"、 "top"、 "right"、 "bottom" 属性进行定位。