国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

jquery 實現返回頂部功能

2019-11-20 13:55:01
字體:
來源:轉載
供稿:網友

今天搞了一個回到頂部的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 id="pubFeedBack"></div>'); 
    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>'); 
    $("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()} 

復制代碼 代碼如下:

#backTop i,#callSurvey i{background:url(survey.png) no-repeat;} 
#pubFeedBack{position:fixed;_position:absolute;right:15px;bottom:15px;width:54px;font-size:12px;} 
#backTop,#callSurvey{display:block;width:52px;padding:1px;height:56px;line-height:22px;text-align:center;color:#fff;text-decoration:none;} 
#backTop{display:none;background:#999;} 
#backTop:hover{background:#ccc;zoom:1;text-decoration:none;color:#fff;} 
#backTop i{display:block;width:25px;height:13px;margin:14px auto 8px;background-position:-63px 0;} 
#callSurvey{margin-top:1px;background:#3687d9;} 
#callSurvey:hover{background:#66a4e3;zoom:1;text-decoration:none;color:#fff;} 
#callSurvey i{display:block;width:26px;height:25px;margin:9px auto 0;background-position:0 0;} 
#callSurvey:hover i{background-position:-30px 0;} 

代碼很簡單,各位直接拿去,放在自己項目中即可,如有bug請給我留言,共同完善

方法二:

主要參數:
scrollName: 'scrollUp', // Element ID
topDistance: '300', // Distance from top before showing element (px)
topSpeed: 300, // Speed back to top (ms)
animation: 'fade', // Fade, slide, none
animationInSpeed: 200, // Animation in speed (ms)
animationOutSpeed: 200, // Animation out speed (ms)
scrollText: 'Scroll to top', // Text for element
activeOverlay: false,
// 幫助定位“回到頂端”按鈕出現時滾動到的頁面位置。

jquery代碼(ScrollUp.js):

$(function () {$.scrollUp({scrollName: 'scrollUp', // Element IDtopDistance: '300', // Distance from top before showing element (px)topSpeed: 300, // Speed back to top (ms)animation: 'fade', // Fade, slide, noneanimationInSpeed: 200, // Animation in speed (ms)animationOutSpeed: 200, // Animation out speed (ms)scrollText: 'Scroll to top', // Text for elementactiveOverlay: false, // set css color to display scrollup active point, e.g '#00ffff'});});
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 新兴县| 田阳县| 金塔县| 师宗县| 湘潭县| 襄樊市| 青州市| 肇东市| 阿拉善盟| 七台河市| 启东市| 嘉禾县| 凤城市| 龙门县| 呈贡县| 桂东县| 和顺县| 红原县| 建瓯市| 平山县| 丰原市| 舞阳县| 襄汾县| 高青县| 绥化市| 光泽县| 天台县| 中山市| 玉门市| 防城港市| 新邵县| 商城县| 丽江市| 武定县| 固原市| 道真| 卢氏县| 兴宁市| 平果县| 安西县| 丹江口市|