使用方法
(function($) {
$.fn.fixedHeaderScroll = function(options) {
var settings = $.extend({
'headerSelector': 'header', // You need to designate the header element in your website.
'offset': 0, // You can offset the scroll position.
'smooth': true, // You can choose if you use smooth scroll or not.
'smoothDuration': 300, // Scroll speed. (in ms)
'smoothEasing': 'linear', // Scroll easing.
}, options);
function fixScroll(targetSlector) {
if (settings.headerSelector == false) {
var h = 0;
} else {
var headerEl = $(settings.headerSelector);
var h = headerEl.outerHeight();
}
var targetEl = $(targetSlector);
if( targetEl.length < 1) {
return false;
}
var t = targetEl.offset().top;
var s = t - h + settings.offset;
if (settings.smooth) {
$("html, body").stop(true, false).animate({
scrollTop: s
}, settings.smoothDuration, settings.smoothEasing);
} else {
$("html, body").scrollTop(s);
}
return $(this);
}
this.unbind( "click.fixedHeaderScroll");
this.bind( "click.fixedHeaderScroll", function (){
fixScroll( $(this).attr("href"));
});
$(window).on('load', function() {
if (location.hash) {
fixScroll(location.hash);
return false;
}
});
};
})(jQuery);
站长提示:
1. 苦力吧素材官方QQ群:
950875342
2. 平台上所有素材资源,需注册登录会员方能正常下载。
3. 会员用户积极反馈网站、素材资源BUG或错误问题,每次奖励
2K币。
4. PHP源码类素材,如需协助安装调试,或你有二次开发需求,可联系苦力吧客服。
5. 付费素材资源,需充值后方能下载,如有任何疑问可直接联系苦力吧客服