Suidhich buaidh cliogadh air an ìomhaigh rocaid jquery scrollaich air ais chun chòd JS gu h-àrd

roinn ciamarWordPressCuir an gnìomh buaidh “cliog air an rocaid gus tilleadh chun mhullach” sa chuspair.

  • Mas e whiz WordPress a th’ annad, tha fios agad mar a ghiùlain thu e gu cuspair WordPress.
  • Tha an artaigil seo cuideachd iomchaidhlàrach-lìn a chruthachadhneach-tòiseachaidh.

Rocket Ascent Air ais chun mhullach dealbh

Cliog air dìreadh na rocaid gus tilleadh chun dealbh gu h-àrd 1

Luchdaich sìos an ìomhaigh gu h-àrd ro làimh, thathas a’ moladh a chuir ann am pasgan nan ìomhaighean fon eòlaire cuspair.

Ceum 1: Luchdaich na faidhlichean leabharlainn jQuery

  • Luchdaich faidhle leabharlann jQuery, ma tha an cuspair WordPress air a luchdachadh mu thràth, faodaidh tu an ceum seo a leigeil seachad;

Bheir WordPress a-steach leabharlann jQuery treas-phàrtaidh, thoir sùil air an oideachadh seo ▼

Ceum 2: Cuir còd ris an fhaidhle footer.php

Cuir an còd a leanas ris an àite iomchaidh anns a’ chuspair footer.php ▼

<div class="one"></div>
<div id="backtotop" style="display:none;"></div>

Ceum 3: Cuir Còd ri CSS File

Cuir an còd CSS a leanas ri faidhle style.css a’ chuspair ▼

.one {width:100%;height:3000px;}
#backtotop {background:url(images/rocket_up.png) 0px 0px no-repeat;position:fixed;bottom:0px;right:10px;width:149px;height:260px;cursor: pointer;z-index:1000;}

Ceum 4: Cuir air ais gu mullach còd JS

Airson a’ chòd js a leanas, faodaidh tu faidhle js eile a chruthachadh;

no cuir còmhla e san fhaidhle js buntainneach de chuspair a tha ann mu thràth (air a mholadh);

no faodaidh tu a phasgadh ann an footer.php Meadhanach ▼

var scrollTT = {
tTSpeed : 800, // 滚动到顶部的时间
startFlyTime : 1000, // 火箭起飞的时间
restartTime : 1200, // 重置火箭位置的时间
flySpeed : 50, // 火箭向上飞行的速度
obj : $("#backtotop"), // 回到顶部的dom
flyTemp : '', // 一个setInterval的临时变量
/**
* 
* 初始化 scrollTT 函数
* 主要是像对象添加事件
*
*/
init : function( obj, tTSpeed, startFlyTime, restartTime, flySpeed ) {
scrollTT.tTSpeed = scrollTT.tTSpeed || tTSpeed;
scrollTT.startFlyTIme = scrollTT.startFlyTIme || startFlyTime;
scrollTT.restartTime = scrollTT.restartTime || restartTime;
scrollTT.flySpeed = scrollTT.flySpeed || flySpeed;
scrollTT.obj = scrollTT.obj || obj;

// 向window 绑定scroll 事件
scrollTT.onScroll();


scrollTT.obj.click(function(){
// 关闭默认的scroll事件
$(window).off("scroll");
// 页面向上滚动
$('html,body').animate({scrollTop: '0px'}, this.tTSpeed);
// 火箭向上飞行
scrollTT.objFly();
// 火箭的喷气效果
scrollTT.blow();

});

// 鼠标在火箭上的效果
scrollTT.obj.mouseenter(function() {
$(this).css('background-position', '-149px 0px');
});
// 鼠标移开的效果
scrollTT.obj.mouseleave(function() {
$(this).css('background-position', '0px 0px');
});

}, 
/*
* 向window 绑定scroll 事件
*
*/
onScroll : function() {
$(window).on('scroll', function() {
if ($(window).scrollTop()>500){
scrollTT.obj.fadeIn(500);
}else{
scrollTT.obj.fadeOut(1500);
}
});
},
/**
* dom对象向上飞行
*
*/
objFly : function() {
var fly = setTimeout(function(){
scrollTT.obj.animate({top: '-500px'} ,'normal', 'swing');
scrollTT.resetFly();
clearTimeout(fly);
clearInterval(scrollTT.flyTemp);
}, scrollTT.startFlyTime);
},
/**
* dom 对象飞行完毕回到原来的位置
*
*/
resetFly : function() {
var fly2 = setTimeout(function() {
scrollTT.obj.hide();
scrollTT.obj.css("top", 'auto');
scrollTT.obj.css("background-position", '0px 0px');
scrollTT.onScroll();
clearTimeout(fly2);
},scrollTT.restartTime);
},
/**
* dom 对象的喷气效果
*
*/
blow : function() {
var topPosiiton = -149;
scrollTT.flyTemp = setInterval(function() {
topPosiiton += -149;
if(topPosiiton < -743) {
topPosiiton = -149
}
scrollTT.obj.css('background-position', topPosiiton + 'px 0px');
}, this.flySpeed);
}
};

scrollTT.init();

 

An dòchas blog Chen Weiliang ( https://www.chenweiliang.com/ ) Co-roinnte “Suidhich Cliog Rocket Icon jQuery Scroll Back to Top JS Code Effect”, bidh e na chuideachadh dhut.

Fàilte gus ceangal an artaigil seo a cho-roinn:https://www.chenweiliang.com/cwl-1491.html

Fàilte don t-sianal Telegram de bhlog Chen Weiliang gus na h-ùrachaidhean as ùire fhaighinn!

🔔 Bi mar a’ chiad fhear a fhuair an “Stiùireadh Cleachdadh Inneal AI Margaidheachd Susbaint ChatGPT” luachmhor ann an eòlaire mullach an t-seanail! 🌟
📚 Tha luach mòr anns an stiùireadh seo, 🌟 Is e cothrom ainneamh a tha seo, na caill e! ⏰⌛💨
Roinn agus toil ma thogras tu!
Is e do roinneadh agus do rudan mar ar brosnachadh leantainneach!

 

发表 评论

Cha tèid do sheòladh puist-d fhoillseachadh. 必填 项 已 用 * Label

sgrolaich gu mullach