一句jQuery代码实现返回顶部效果(简单实用)

只需引用jQuery库和YesTop插件,然后一句代码就可以实现返回顶部:

引用代码:

<script type="text/javascript" src="https://hovertree.com/ziyuan/jquery/jquery-1.11.3.min.js"></script> <script type="text/javascript" src="https://hovertree.com/texiao/yestop/inc/jquery.yestop.js"></script>

使用代码:

<script type="text/javascript"> $(document).ready(function () { $.fn.yestop(); }) </script>

也就是:

$.fn.yestop();

这句代码就可以了。

当然还有高级的设置,如换图片,设置图标为圆形,设置位置,设置时间等等。详情请查看其他Demo。

完整代码,保存到HTML文件就可以体验效果:

<!DOCTYPE html> <html> <head><meta charset="UTF-8"> <title>YesTop - HoverTree</title><meta content="width=device-width, initial-scale=1.0"> <script type="text/javascript" src="https://hovertree.com/ziyuan/jquery/jquery-1.11.3.min.js"></script> <script type="text/javascript" src="https://hovertree.com/texiao/yestop/inc/jquery.yestop.js"></script> <style> body { margin: 0px;font-family:Arial }a{color:blue} </style> </head> <body> <div> <h1>YesTop</h1> A jQuery Plugin<br /> <a href="https://hovertree.com/texiao/yestop/">Demo 1</a> <a href="https://hovertree.com/texiao/yestop/demo2.htm">Demo 2</a> <a href="https://hovertree.com/texiao/yestop/demo3.htm">Demo 3</a> <a href="https://hovertree.com/texiao/yestop/demo4.htm">Demo 4</a> <a href="https://hovertree.com/h/bjaf/topimage.htm">Images</a> </div> <div> </div> <div>&copy; hovertree.com</div> <div> </div><div></div><div></div> <div> </div> <div></div> <div></div> <div></div> <div></div> <div></div> <script type="text/javascript"> $(document).ready(function () { $.fn.yestop(); }) </script> </body> </html>

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wwjjxf.html