Created
April 11, 2013 07:12
-
-
Save livem/5361362 to your computer and use it in GitHub Desktop.
"返回顶部"插件
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@CHARSET "UTF-8"; | |
.backToTop { | |
width: 100px; | |
z-index: 10; | |
border: 1px solid #333; | |
background: #121212; | |
text-align: center; | |
padding: 5px; | |
position: fixed; | |
bottom: 0px; | |
right: 0px; | |
cursor: pointer; | |
display: none; | |
color: #fff; | |
text-transform: lowercase; | |
font-size: 0.9em; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* jQuery BackToTop plugin 返回顶部 | |
* | |
* 2013-01-23 | |
* | |
* @require jQuery | |
* @require backToTop.css | |
* @link 参考自 http://www.cnblogs.com/lanmiao/articles/2248053.html | |
* | |
* eg: $('html').createBackToTop(); | |
* 或 $('body').createBackToTop(); | |
* 或 $( window ).createBackToTop(); | |
* | |
*/ | |
;(function( win ){ | |
var _win = win, _doc = _win.document, $ = _win.jQuery; | |
$.fn.createBackToTop = function() { | |
var scrollDiv = _doc.createElement('div'); | |
$(scrollDiv).addClass('backToTop').html( '\u8FD4\u56DE\u9876\u90E8' ).appendTo('body'); // window.escape('返回顶部') | |
$( _win ).scroll(function() { | |
if ($(this).scrollTop() != 0) { | |
$('.backToTop').fadeIn(); | |
} else { | |
$('.backToTop').fadeOut(); | |
} | |
}); | |
$('.backToTop').click(function() { | |
$('body,html').animate({ scrollTop: 0 }, 800); | |
}); | |
}; | |
/** | |
* 判断当前元素是否存在 | |
* | |
* @return {Boolean} true 代表存在 | |
*/ | |
$.fn.isExist = function() { | |
return ( $(this).length > 0 ); | |
}; | |
})( window ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment