今天搞了一个回到顶部的JS JQ功能,废话不多说,有图有真相!
复制代码 代码如下:
(function($){
$.fn.survey=function(options){
var defaults={width:"298",height:"207"};
var options=$.extend(defaults,options);
if($.browser.msie){
var ieVersion=parseInt($.browser.version)}
//建立HTML
var __feedCreat=function(){
var feedHtml=$('<div></div>');
feedHtml.html('<a href="#top"><i></i>\u8fd4\u56de\u9876\u90e8</a><a href="#"><i></i>\u610f\u89c1\u53cd\u9988</a>');
$("body").append(feedHtml);
__ie6Fixed()
};
//绑定事件
var __initEvent=function(){
$(window).resize(function(){
var winW=$(this).width();
if(winW<=1124){$("#pubFeedBack").hide()}
else{$("#pubFeedBack").show()}
});
$(window).bind("scroll",function(){
if($(this).scrollTop()>50){
$("#backTop").fadeIn().css({"display":"block"})
}
else{$("#backTop").fadeOut().css({"display":""})}
});
$("#backTop").bind("click",function(e){
e.preventDefault();
$("html,body").scrollTop(0)});
};
//回到顶部
var __tip=function(type,tipText){
var surveyTip=$("#D_SurveyTip"),surveyMask=$("#D_SurveyMask");
if(!surveyTip||!surveyMask){return}
surveyTip.removeClass("warning success").addClass(type).html(tipText);
surveyMask.css("display","block");
surveyTip.css("display","block");
setTimeout(function(){
surveyMask.css("display","none"); surveyTip.css("display","none")},1000)
};
//ie6兼容
var __ie6Fixed=function(){
if(ieVersion!==6){return}
var surveyBox=$("#D_SurveyBox");
var pubFeedBack=$("#pubFeedBack");
if(!surveyBox||!pubFeedBack)
{
return
}
$(window).bind("scroll",function(){
var h=$(window).height(),st=$(window).scrollTop(),_top=h+st-options.height; var _top1=h+st-pubFeedBack.height()-15;surveyBox.css("top",_top+"px");
pubFeedBack.css("top",_top1+"px")
})
};
//开始执行
if(screen.width>=1280)
{
(function(){
__feedCreat(); __initEvent() })()
}
}
})(jQuery);
window.onerror=function(){return false};
if($.isFunction($(document).survey)){$(document).survey()}
复制代码 代码如下: