这次给大家带来jQuery实现分章节锚点回到顶部效果,jQuery实现分章节锚点回到顶部的注意事项有哪些,下面就是实战案例,一起来看一下。
这里演示基于jquery实现的分章节动画实现“回到顶部”的效果,可通过 网页顶部的数字序号直接进入网页的章节,当处于第二章节的时候,网页右侧会显示竖排的控制按钮,点击按钮会回到相应章节,其实也就是定义好的锚点,当然也可回到顶部,网页上见到的回顶部大多不是这个样子,所以本款效果还挺新颖。
运行效果截图如下:
具体代码如下:
nbsp;html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <title>jQuery锚点带动画跳转特效</title> <script></script> <style> .gray { -webkit-filter: grayscale(100%); -moz-filter: grayscale(100%); -ms-filter: grayscale(100%); -o-filter: grayscale(100%); filter: grayscale(100%); filter: gray; } /* reset */ body, p, dl, dt, dd, ul, ol, li, h1, h2, h3, h4, h5, h6, p , form, fieldset, legend, input, button, textarea, th, td { margin:0; padding:0; } table { border-collapse:collapse; border-spacing:0; } fieldset, img { border:0; } ul,li { list-style:none; } body { background: #f1f1f1; color: #666; font:12px/1.7 Helvetica,Arial,Tahoma,sans-serif,"\5B8B\4F53"; } .row:after { clear:both; content:'\0020'; display:block; height:0; } .row { zoom:1; } /*链接颜色*/ a,button{outline:none; /*移除虚线框 IE8,FF有用*/ hide-focus: expression(this.hideFocus=true); /*IE6、IE7*/} a{ color:#999; text-decoration:none; } a:hover{ color:#be0000; text-decoration: underline; } .fst{ font-family: "\5B8B\4F53"; } h1,h2,h3,h4,h5,h6{font-family:\5FAE\8F6F\96C5\9ED1; font-size: 16px;} /* end reset */ .row{ width:1000px; margin:0 auto; } /*模板头部,所有专题页面公用*/ .index_nav{width:575px; height: 70px; margin: 0 auto; padding-left: 5px; background: #fff;} .index_nav li{width: 115px; height: 70px; float: left;} .index_nav li a{display: block; float: left; width: 70px;height: 70px; background:url(images/index_nav.gif) 0 0 no-repeat; text-align: center; color: #e02800;} .index_nav li a i{display: block; padding-top: 12px; height: 22px; line-height: 22px;} .index_nav li a strong{font-family: Arial, Helvetica, sans-serif; font-weight: bold; font-size: 24px; display: block; height: 30px; line-height: 20px;} .index_nav li a:hover{background-position: 0 -70px; color: #fff; text-decoration: none;} .h15{height: 15px; overflow: hidden;} .mainpage{width: 1000px; height:1000px;} h2{font-size: 24px; text-align: center; color: #333; font-weight: bold;} .mainpage p{width: 650px; margin: 0 auto; color: #fff; font-size: 16px; padding: 50px 0 50px;} .mainpage1{background: #fe6400;} .mainpage2{background: #be0000;} .mainpage3{background: #ccc;} .mainpage4{background: #0093dd;} .mainpage5{background: #a8cf33;} *html{background-image:url(about:blank);background-attachment:fixed;}/*低版本浏览器防止抖动的,必须有*/ #tbox{width:30px; height:200px; float:right; position:fixed; display: none; _position:absolute; _bottom:auto; _top:expression(eval(document.documentElement.scrollTop+document.documentElement.clientHeight-this.offsetHeight-(parseInt(this.currentStyle.marginTop,10)||0)-(parseInt(this.currentStyle.marginBottom,10)||0))); _margin-bottom:50px; }/*这个只能改宽高其他的不要修改,需要滚动的内容都要放在这个p里面*/ .taoba{display:block; background:#c2c2c2; width:30px; height:30px; margin-bottom:4px;text-align: center; color: #fff; line-height: 30px; overflow: hidden;cursor:pointer} .taoba:hover{background:#ff4200; text-decoration: none; color: #fff;} #gotop{display:block; width:30px; height:30px; text-indent:-9999px; overflow: hidden; color: #fff; background:url(images/top_icon.gif) no-repeat; position:absolute; display:none; cursor:pointer} /*这个样式随便改,必须有position:absolute; */ #gotop:hover{background-position: 0 -30px;} </style> <script> jQuery(document).ready(function($) { $(".index_nav li a").click(function(event) { var index=this.title var id='#'+'index_'+index $("html,body").animate({scrollTop: $(id).offset().top}, 1000); }); $(".taoba").click(function(event) { var index=this.title var id='#'+'index_'+index $("html,body").animate({scrollTop: $(id).offset().top}, 1000); }); function a(x,y){ l = $('#main').offset().left; w = $('#main').width(); $('#tbox').css('left',(l + w + x) + 'px'); $('#tbox').css('bottom',y + 'px'); }//获取#tbox的p距浏览器底部和页面内容区域右侧的距离函数#main为页面的可视宽度 $(function() { $(window).scroll(function(){ t = $(document).scrollTop(); if(t>500){ $('#tbox').show(); }else{ $('#tbox').hide(); } if(t > 50){ $('#gotop').fadeIn('slow'); }else{ $('#gotop').fadeOut('slow'); } }) a(10,100);//#tbox的p距浏览器底部和页面内容区域右侧的距离 $('#gotop').click(function(){ $('body,html').animate({ scrollTop: 0 }, 800);//点击回到顶部按钮,缓懂回到顶部,数字越小越快 return false; }) }); }); </script> <p> </p>
这是第一个活动页
这是第二个活动页
这是第三个活动页
这是第四个活动页
这是第五个活动页
相信看了本文案例你已经掌握了方法,更多精彩请关注php中文网其它相关文章!
推荐阅读:
The above is the detailed content of jQuery implements chapter anchor point return to top effect. For more information, please follow other related articles on the PHP Chinese website!

JavaScript runs in browsers and Node.js environments and relies on the JavaScript engine to parse and execute code. 1) Generate abstract syntax tree (AST) in the parsing stage; 2) convert AST into bytecode or machine code in the compilation stage; 3) execute the compiled code in the execution stage.

The future trends of Python and JavaScript include: 1. Python will consolidate its position in the fields of scientific computing and AI, 2. JavaScript will promote the development of web technology, 3. Cross-platform development will become a hot topic, and 4. Performance optimization will be the focus. Both will continue to expand application scenarios in their respective fields and make more breakthroughs in performance.

Both Python and JavaScript's choices in development environments are important. 1) Python's development environment includes PyCharm, JupyterNotebook and Anaconda, which are suitable for data science and rapid prototyping. 2) The development environment of JavaScript includes Node.js, VSCode and Webpack, which are suitable for front-end and back-end development. Choosing the right tools according to project needs can improve development efficiency and project success rate.

Yes, the engine core of JavaScript is written in C. 1) The C language provides efficient performance and underlying control, which is suitable for the development of JavaScript engine. 2) Taking the V8 engine as an example, its core is written in C, combining the efficiency and object-oriented characteristics of C. 3) The working principle of the JavaScript engine includes parsing, compiling and execution, and the C language plays a key role in these processes.

JavaScript is at the heart of modern websites because it enhances the interactivity and dynamicity of web pages. 1) It allows to change content without refreshing the page, 2) manipulate web pages through DOMAPI, 3) support complex interactive effects such as animation and drag-and-drop, 4) optimize performance and best practices to improve user experience.

C and JavaScript achieve interoperability through WebAssembly. 1) C code is compiled into WebAssembly module and introduced into JavaScript environment to enhance computing power. 2) In game development, C handles physics engines and graphics rendering, and JavaScript is responsible for game logic and user interface.

JavaScript is widely used in websites, mobile applications, desktop applications and server-side programming. 1) In website development, JavaScript operates DOM together with HTML and CSS to achieve dynamic effects and supports frameworks such as jQuery and React. 2) Through ReactNative and Ionic, JavaScript is used to develop cross-platform mobile applications. 3) The Electron framework enables JavaScript to build desktop applications. 4) Node.js allows JavaScript to run on the server side and supports high concurrent requests.

Python is more suitable for data science and automation, while JavaScript is more suitable for front-end and full-stack development. 1. Python performs well in data science and machine learning, using libraries such as NumPy and Pandas for data processing and modeling. 2. Python is concise and efficient in automation and scripting. 3. JavaScript is indispensable in front-end development and is used to build dynamic web pages and single-page applications. 4. JavaScript plays a role in back-end development through Node.js and supports full-stack development.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

SublimeText3 Chinese version
Chinese version, very easy to use

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.
