当前位置:   article > 正文

html返回顶部按钮图片,goToTop(回到顶部)按钮的制作

gototop

//GoTop mg12

GoTop = function() {

this.config = {

pageWidth : 960,//页面宽度

nodeId : 'go-top',//回到顶部按钮的ID

nodeWidth : 50,//按钮宽度

distanceToBottom : 120,//距离底部高度

hideRegionHeight : 90,//消失高度

text : ''

};

this.cache = {

topLinkThread : null

}

};

GoTop.prototype = {

init : function(config) {

this.config = config || this.config;

var _self = this;

jQuery(window).scroll(function() {

_self._scrollScreen({

_self : _self

});

});

jQuery(window).resize(function() {

_self._resizeWindow({

_self : _self

});

});

_self._insertNode({

_self : _self

});

},

_insertNode : function(args) {

var _self = args._self;

var topLink = jQuery('' + _self.config.text + '');

topLink.appendTo(jQuery('body'));

if(jQuery.scrollTo) {

topLink.click(function() {

jQuery.scrollTo({

top : 0

}, 400);

return false;

});

}

var right = _self._getDistanceToBottom({

_self : _self

});

if(/MSIE 6/i.test(navigator.userAgent)) {

topLink.css({

'display' : 'none',

'position' : 'absolute',

'right' : right + 'px'

});

} else {

topLink.css({

'display' : 'none',

'position' : 'fixed',

'right' : right + 'px',

'top' : (jQuery(window).height() - _self.config.distanceToBottom) + 'px'

});

}

},

_scrollScreen : function(args) {

var _self = args._self;

var topLink = jQuery('#' + _self.config.nodeId);

if(jQuery(document).scrollTop() <= _self.config.hideRegionHeight) {

clearTimeout(_self.cache.topLinkThread);

topLink.hide();

return;

}

if(/MSIE 6/i.test(navigator.userAgent)) {

clearTimeout(_self.cache.topLinkThread);

topLink.hide();

_self.cache.topLinkThread = setTimeout(function() {

var top = jQuery(document).scrollTop() + jQuery(window).height() - _self.config.distanceToBottom;

topLink.css({

'top' : top + 'px'

}).fadeIn();

}, 400);

} else {

topLink.fadeIn();

}

},

_resizeWindow : function(args) {

var _self = args._self;

var topLink = jQuery('#' + _self.config.nodeId);

var right = _self._getDistanceToBottom({

_self : _self

});

var top = jQuery(window).height() - _self.config.distanceToBottom;

if(/MSIE 6/i.test(navigator.userAgent)) {

top += jQuery(document).scrollTop();

}

topLink.css({

'right' : right + 'px',

'top' : top + 'px'

});

},

_getDistanceToBottom : function(args) {

var _self = args._self;

var right = parseInt((jQuery(window).width() - _self.config.pageWidth) / 2 - _self.config.nodeWidth - 20, 10);

if(right < 10) {

right = 10;

}

return right;

}

};

//GoTop mg12

GoTop = function() {

this.config = {

pageWidth : 960,//页面宽度

nodeId : 'go-top',//回到顶部按钮的ID

nodeWidth : 50,//按钮宽度

distanceToBottom : 120,//距离底部高度

hideRegionHeight : 90,//消失高度

text : ''

};

this.cache = {

topLinkThread : null

}

};

GoTop.prototype = {

init : function(config) {

this.config = config || this.config;

var _self = this;

jQuery(window).scroll(function() {

_self._scrollScreen({

_self : _self

});

});

jQuery(window).resize(function() {

_self._resizeWindow({

_self : _self

});

});

_self._insertNode({

_self : _self

});

},

_insertNode : function(args) {

var _self = args._self;

var topLink = jQuery('' + _self.config.text + '');

topLink.appendTo(jQuery('body'));

if(jQuery.scrollTo) {

topLink.click(function() {

jQuery.scrollTo({

top : 0

}, 400);

return false;

});

}

var right = _self._getDistanceToBottom({

_self : _self

});

if(/MSIE 6/i.test(navigator.userAgent)) {

topLink.css({

'display' : 'none',

'position' : 'absolute',

'right' : right + 'px'

});

} else {

topLink.css({

'display' : 'none',

'position' : 'fixed',

'right' : right + 'px',

'top' : (jQuery(window).height() - _self.config.distanceToBottom) + 'px'

});

}

},

_scrollScreen : function(args) {

var _self = args._self;

var topLink = jQuery('#' + _self.config.nodeId);

if(jQuery(document).scrollTop() <= _self.config.hideRegionHeight) {

clearTimeout(_self.cache.topLinkThread);

topLink.hide();

return;

}

if(/MSIE 6/i.test(navigator.userAgent)) {

clearTimeout(_self.cache.topLinkThread);

topLink.hide();

_self.cache.topLinkThread = setTimeout(function() {

var top = jQuery(document).scrollTop() + jQuery(window).height() - _self.config.distanceToBottom;

topLink.css({

'top' : top + 'px'

}).fadeIn();

}, 400);

} else {

topLink.fadeIn();

}

},

_resizeWindow : function(args) {

var _self = args._self;

var topLink = jQuery('#' + _self.config.nodeId);

var right = _self._getDistanceToBottom({

_self : _self

});

var top = jQuery(window).height() - _self.config.distanceToBottom;

if(/MSIE 6/i.test(navigator.userAgent)) {

top += jQuery(document).scrollTop();

}

topLink.css({

'right' : right + 'px',

'top' : top + 'px'

});

},

_getDistanceToBottom : function(args) {

var _self = args._self;

var right = parseInt((jQuery(window).width() - _self.config.pageWidth) / 2 - _self.config.nodeWidth - 20, 10);

if(right < 10) {

right = 10;

}

return right;

}

};

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/菜鸟追梦旅行/article/detail/110465?site
推荐阅读
相关标签
  

闽ICP备14008679号