純js實(shí)現(xiàn)懸浮按鈕組件
更新時(shí)間:2016年12月17日 17:15:43 作者:yyyuuu777
這篇文章主要為大家詳細(xì)介紹了純js實(shí)現(xiàn)懸浮按鈕組件的使用方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
先上效果
下面附上代碼 使用方式很簡單只需要 在頁面引入這段js 即可
$(()=> { let param = { tag: true, num: 1, ele: document.createElement('div'), icon: '', homeIcon: '', moreIcon: '', personalIcon: '', closeIcon: '', distance: '500', css: "position:fixed;" + "bottom:4rem;" + "box-shadow:10px 10px 10px gray;" + "right:10px;" + "display:none;" + "font-size:1.5rem;" + "color:#fff;" + "z-index:1000;" + "height:2.5rem;" + "width:2.5rem;" + "background:#f44336;" + "border-radius:50%;" + "line-height:2.5rem;" + "text-align:center", menuCss: "position:absolute;" + // "bottom:3rem;" + "display:none;" + "box-shadow:10px 10px 10px gray;" + "font-size:1.2rem;" + "color:#fff;" + "background:orange;" + "height:2rem;" + "width:2rem;" + "border-radius:50%;" + "text-align:center;" + "line-height:2rem;" // type: '#top' }; { document.querySelector('body').appendChild(((ele)=> { ele.className = 'scroll iconfont'; ele.innerHTML = param.moreIcon; // ele.href = param.type; ele.style.cssText = param.css; for (let i = 0; i < 3; i++) { let menu_personal = document.createElement('a'); menu_personal.className = 'iconfont'; menu_personal.style.cssText = param.menuCss; switch (i) { case 0: setStyle(menu_personal, '#2196f3', '2.4rem', '2.4rem', param.homeIcon, 'home'); break; case 1: setStyle(menu_personal, '#4caf50', 0, '3.5rem', param.personalIcon, 'personal'); break; case 2: setStyle(menu_personal, '#fdd835', '3.5rem', '0', param.icon, 'top'); break; } param.ele.appendChild(menu_personal); } return ele; })(param.ele)); function setStyle(ele, ...args) { ele.style.background = args[0]; ele.style.bottom = args[1]; ele.style.right = args[2]; ele.innerHTML = args[3]; ele.id = args[4]; } } { $(window).scroll(()=> { var scrollValue = $(window).scrollTop(); if (scrollValue > param.distance) { if (param.tag) { $(param.ele).css('display', 'block').animateCss('fadeInRight'); param.tag = !param.tag; } } else { if (!param.tag) { $(param.ele).css('display', 'none'); $(param.ele).children().css('display', 'none'); param.num++; param.tag = !param.tag; } } }); $(param.ele).click((e)=> { window.e = e; switch (e.target.id) { case 'home': if (!getTypeNative()) { window.location.href = getAbsolutePath() + '/fenqihui/pages/recommended/recommended_index.html'; } else if (getTypeNative() === 'ios') { backHome(); } else if (getTypeNative() === 'android') { android.backHome(); } break; case 'personal': if (!getTypeNative()) { window.location.href = getAbsolutePath() + '/fenqihui/pages/account/user_personal.html'; } else if (getTypeNative() === 'ios') { //todo://前往個(gè)人中心 backAccount(); } else if (getTypeNative() === 'android') { android.backAccount(); } break; case 'top': $(window).scrollTop(0); break; } param.num % 2 == 0 && $(param.ele).children().css('display', 'none') || $(param.ele).children().css('display', 'block').animateCss('swing'); param.num++; }) } });
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
JavaScript關(guān)鍵字this的使用方法詳解
與其他語言相比,函數(shù)的 this 關(guān)鍵字在 JavaScript 中的表現(xiàn)略有不同,此外,在嚴(yán)格模式和非嚴(yán)格模式之間也會(huì)有一些差別,本文就給大家講解一下JavaScript關(guān)鍵字中的this,需要的朋友可以參考下2023-08-08js實(shí)現(xiàn)類似菜單風(fēng)格的TAB選項(xiàng)卡效果代碼
這篇文章主要介紹了js實(shí)現(xiàn)類似菜單風(fēng)格的TAB選項(xiàng)卡效果代碼,通過javascript鼠標(biāo)事件及頁面元素遍歷實(shí)現(xiàn)tab切換的功能,非常簡單實(shí)用,需要的朋友可以參考下2015-08-08如何使用js正則表達(dá)式驗(yàn)證文件夾名是否符合規(guī)范
眾所周知正則表達(dá)式非常強(qiáng)大,下面這篇文章主要給大家介紹了關(guān)于如何使用js正則表達(dá)式驗(yàn)證文件夾名是否符合規(guī)范的相關(guān)資料,文中通過實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下2023-05-05詳解JavaScript數(shù)據(jù)類型和判斷方法
這篇文章主要介紹了JavaScript數(shù)據(jù)類型和判斷方法的相關(guān)資料,幫助大家更好的理解和學(xué)習(xí)JavaScript,感興趣的朋友可以了解下2020-09-09javascript算法題:求任意一個(gè)1-9位不重復(fù)的N位數(shù)在該組合中的大小排列序號
這篇文章主要介紹了javascript算法題:求任意一個(gè)1-9位不重復(fù)的N位數(shù)在該組合中的大小排列序號,需要的朋友可以參考下2015-04-04淺析javascript異步執(zhí)行函數(shù)導(dǎo)致的變量變化問題解決思路
下面小編就為大家?guī)硪黄獪\析javascript異步執(zhí)行函數(shù)導(dǎo)致的變量變化問題解決思路。小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考2016-05-05