jQuery返回顶部插件jQuery.toTop
当长度超过滚动条的高度后会显示 top 按钮

XML/HTML Code
- 1、引入文件
- <script src="jsjquery.min.js"></script>
- <script src="js/jquery.toTop.min.js"></script>
- 2、HTML
- <a class="to-top">返回顶部</a>
- 3、JavaScript
- $('.to-top').toTop();
JavaScript Code
- /**
- * Plugin Name: jQuery toTop for smoothly Scroll back to Top
- * Plugin URL: https://github.com/mmkjony/jQuery.toTop
- * Version: 1.1
- * Author: MMK Jony
- * Author URL: https://github.com/mmkjony
- * License: Licensed under MIT
- **/
- (function( $ ){
- 'use strict';
- $.fn.toTop = function(opt){
- //variables
- var elem = this;
- var win = $(window);
- var doc = $('html, body');
- //Extended Options
- var options = $.extend({
- autohide: true,
- offset: 420,
- speed: 500,
- position: true,
- right: 15,
- bottom: 30
- }, opt);
- elem.css({
- 'cursor': 'pointer'
- });
- if(options.autohide){
- elem.css('display', 'none');
- }
- if(options.position){
- elem.css({
- 'position': 'fixed',
- 'right': options.right,
- 'bottom': options.bottom,
- });
- }
- elem.click(function(){
- doc.animate({scrollTop: 0}, options.speed);
- });
- win.scroll(function(){
- var scrolling = win.scrollTop();
- if(options.autohide){
- if(scrolling > options.offset){
- elem.fadeIn(options.speed);
- }
- else elem.fadeOut(options.speed);
- }
- });
- };
- }( jQuery ));
原文地址:http://www.freejs.net/article_jquerywenzi_472.html
最近更新
- CSS3鼠标悬停图片遮罩层变形动画特...
- 响应式全屏手风琴菜单,同时支持垂直方...
- 分组select选择器,支持多选和单...
- jQuery时间日期选择器代码日历插...
- Select 选择器 可以清空的单选...
- jQuery json 无刷新翻页 ...
我爱薅羊毛
点击最多
广告赞助
相关文章
- jquery点击显示或隐藏内容,可以一次展开多个和...
- tooltips/弹出层/消息提示效果,支持点击与...
- jQuery幸运大转盘抽奖活动代码
- jquery来实现的添加商品和减少商品数量,用于购...
- jQuery手机端弹出层提示对话框
- php js实现拖动滑块完成拼图验证码