html用锚点回到顶部代码,纯css实现回到顶部-jq回到顶部方法

本文介绍了如何使用纯CSS和jQuery的animate()方法实现页面锚点跳转的平滑过渡效果,包括两种不同的滚动距离设定,并详细讲解了如何用CSS和JavaScript返回顶部按钮的制作与滚动效果控制。
摘要由CSDN通过智能技术生成

//锚点跳转平滑过渡距离顶部距离0

$('.floor-bar-left a').click(function(){

$('html, body').animate({

scrollTop: $( $.attr(this, 'href') ).offset().top

}, 300);

return false;

});

//锚点跳转平滑过渡距离顶部距离100

$('.floor-bar-left a').click(function(){

$('html, body').animate({

scrollTop: $( $.attr(this, 'href') ).offset().top - 100

}, 300);

return false;

});

方法一:纯css实现回到顶部

html>

纯css回到顶部

position:fixed; right:20px; bottom:20px;">回到
顶部

方法二:jq的animate()方法

html>

回到顶部

.f_conct {background-color: #0d5baa;position: fixed;  z-index: 9999999;

top: 200px;  right: -10px;  cursor: pointer;  transition: all .3s ease;  }

.f_bar .f_top {background: #0d5baa url(images/fiex.png) no-repeat 0 -8px;  }

  • 返回顶部

------重点!!!!!!!------

$(".f_top").click(function(){

$("html,body").animate({

'scrollTop':'0'

},300);

});

/*如有侵权,请联系删除

scrollTop() 方法返回或设置匹配元素的滚动条的垂直位置。

scroll top offset 指的是滚动条相对于其顶部的偏移。

嵌套animate()方法的解释---(来自w3cschool)

jQuery animate() 方法用于创建自定义动画。

语法:

$(selector).animate({params},speed,callback);

必需的 params 参数定义形成动画的 CSS 属性        。

可选的 speed 参数规定效果的时长。它可以取以下值:"slow"、"fast" 或毫秒。

可选的 callback 参数是动画完成后所执行的函数名称。

下面的例子演示 animate() 方法的简单应用;它把 

 元素移动到左边,直到 left

属性等于 250 像素为止:

实例

$("button").click(function(){

$("div").animate({left:'250px'});

}); */

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值