jquery 實(shí)現(xiàn)返回頂部功能
今天搞了一個(gè)回到頂部的JS JQ功能,廢話不多說(shuō),有圖有真相!


(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")
})
};
//開(kāi)始執(zhí)行
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;}
代碼很簡(jiǎn)單,各位直接拿去,放在自己項(xiàng)目中即可,如有bug請(qǐng)給我留言,共同完善
方法二:
主要參數(shù):
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,
// 幫助定位“回到頂端”按鈕出現(xiàn)時(shí)滾動(dòng)到的頁(yè)面位置。
jquery代碼(ScrollUp.js):
$(function () {
$.scrollUp({
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,
// set css color to display scrollup active point, e.g '#00ffff'
});
});
- jquery小火箭返回頂部代碼分享
- jQuery實(shí)現(xiàn)返回頂部效果的方法
- jQuery實(shí)現(xiàn)返回頂部功能適合不支持js的瀏覽器
- 用jQuery實(shí)現(xiàn)的智能隱藏、滑動(dòng)效果的返回頂部代碼
- js+JQuery返回頂部功能如何實(shí)現(xiàn)
- 仿新浪微博返回頂部的jquery實(shí)現(xiàn)代碼
- ASP.NET jQuery 實(shí)例9 通過(guò)控件hyperlink實(shí)現(xiàn)返回頂部效果
- 基于jquery的返回頂部效果(兼容IE6)
- JQuery 動(dòng)畫(huà)卷頁(yè) 返回頂部 動(dòng)畫(huà)特效(兼容Chrome)
- jQuery中頁(yè)面返回頂部的方法總結(jié)
相關(guān)文章
jquery遍歷table的tr獲取td的值實(shí)現(xiàn)方法
下面小編就為大家?guī)?lái)一篇jquery遍歷table的tr獲取td的值實(shí)現(xiàn)方法。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2016-05-05
JQ圖片文件上傳之前預(yù)覽功能的簡(jiǎn)單實(shí)例(分享)
下面小編就為大家?guī)?lái)一篇JQ圖片文件上傳之前預(yù)覽功能的簡(jiǎn)單實(shí)例。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-11-11
jquery實(shí)現(xiàn)表格無(wú)縫滾動(dòng)
這篇文章主要為大家詳細(xì)介紹了jquery實(shí)現(xiàn)表格無(wú)縫滾動(dòng),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-06-06
文本溢出插件jquery.dotdotdot.js使用方法詳解
這篇文章主要介紹了文本溢出插件jquery.dotdotdot.js使用方法詳解,需要的朋友可以參考下2017-06-06
利用jQuery對(duì)無(wú)序列表排序的簡(jiǎn)單方法
下面小編就為大家?guī)?lái)一篇利用jQuery對(duì)無(wú)序列表排序的簡(jiǎn)單方法。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2016-10-10
jQuery EasyUI datagrid在翻頁(yè)以后仍能記錄被選中行的實(shí)現(xiàn)代碼
這篇文章主要介紹了jQuery EasyUI datagrid在翻頁(yè)以后仍能記錄被選中行的實(shí)現(xiàn)代碼的相關(guān)資料,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下2016-08-08
jQuery插件實(shí)現(xiàn)非常實(shí)用的tab欄切換功能【案例】
這篇文章主要介紹了jQuery插件實(shí)現(xiàn)非常實(shí)用的tab欄切換功能,涉及jQuery事件響應(yīng)及頁(yè)面元素屬性動(dòng)態(tài)操作相關(guān)實(shí)現(xiàn)技巧,需要的朋友可以參考下2019-02-02

