jquery javascript 回到顶部功能

时间:2020-12-06 22:19:59

今天搞了一个回到顶部的JS JQ功能

jquery javascript 回到顶部功能

jquery javascript 回到顶部功能

  1. (function($){
  2. $.fn.survey=function(options){
  3. var defaults={width:"298",height:"207"};
  4. var options=$.extend(defaults,options);
  5. if($.browser.msie){
  6. var ieVersion=parseInt($.browser.version)}
  7. //建立HTML
  8. var __feedCreat=function(){
  9. var feedHtml=$('<div id="pubFeedBack"></div>');
  10. feedHtml.html('<a href="#top" id="backTop"><i></i>\u8fd4\u56de\u9876\u90e8</a><a href="#" id="callSurvey"><i></i>\u610f\u89c1\u53cd\u9988</a>');
  11. $("body").append(feedHtml);
  12. __ie6Fixed()
  13. };
  14. //绑定事件
  15. var __initEvent=function(){
  16. $(window).resize(function(){
  17. var winW=$(this).width();
  18. if(winW<=1124){$("#pubFeedBack").hide()}
  19. else{$("#pubFeedBack").show()}
  20. });
  21. $(window).bind("scroll",function(){
  22. if($(this).scrollTop()>50){
  23. $("#backTop").fadeIn().css({"display":"block"})
  24. }
  25. else{$("#backTop").fadeOut().css({"display":""})}
  26. });
  27. $("#backTop").bind("click",function(e){
  28. e.preventDefault();
  29. $("html,body").scrollTop(0)});
  30. };
  31. //回到顶部
  32. var __tip=function(type,tipText){
  33. var surveyTip=$("#D_SurveyTip"),surveyMask=$("#D_SurveyMask");
  34. if(!surveyTip||!surveyMask){return}
  35. surveyTip.removeClass("warning success").addClass(type).html(tipText);
  36. surveyMask.css("display","block");
  37. surveyTip.css("display","block");
  38. setTimeout(function(){
  39. surveyMask.css("display","none");                                                                                                                                                                                                                                                                                       surveyTip.css("display","none")},1000)
  40. };
  41. //ie6兼容
  42. var __ie6Fixed=function(){
  43. if(ieVersion!==6){return}
  44. var surveyBox=$("#D_SurveyBox");
  45. var pubFeedBack=$("#pubFeedBack");
  46. if(!surveyBox||!pubFeedBack)
  47. {
  48. return
  49. }
  50. $(window).bind("scroll",function(){
  51. var h=$(window).height(),st=$(window).scrollTop(),_top=h+st-options.height;                                                                                                                                                         var _top1=h+st-pubFeedBack.height()-15;surveyBox.css("top",_top+"px");
  52. pubFeedBack.css("top",_top1+"px")
  53. })
  54. };
  55. //开始执行
  56. if(screen.width>=1280)
  57. {
  58. (function(){
  59. __feedCreat();                                                                                                                                          __initEvent()                                                                                                                                                       })()
  60. }
  61. }
  62. })(jQuery);
  63. window.onerror=function(){return false};
  64. if($.isFunction($(document).survey)){$(document).survey()}
  1. #backTop i,#callSurvey i{background:url(survey.png) no-repeat;}
  2. #pubFeedBack{position:fixed;_position:absolute;right:15px;bottom:15px;width:54px;font-size:12px;}
  3. #backTop,#callSurvey{display:block;width:52px;padding:1px;height:56px;line-height:22px;text-align:center;color:#fff;text-decoration:none;}
  4. #backTop{display:none;background:#999;}
  5. #backTop:hover{background:#ccc;zoom:1;text-decoration:none;color:#fff;}
  6. #backTop i{display:block;width:25px;height:13px;margin:14px auto 8px;background-position:-63px 0;}
  7. #callSurvey{margin-top:1px;background:#3687d9;}
  8. #callSurvey:hover{background:#66a4e3;zoom:1;text-decoration:none;color:#fff;}
  9. #callSurvey i{display:block;width:26px;height:25px;margin:9px auto 0;background-position:0 0;}
  10. #callSurvey:hover i{background-position:-30px 0;}