2020-07-30 Vue電商滾動(dòng)

https://www.cnblogs.com/viete/p/12395548.html

<template>


? <div class="good">


? ? <div class="good-hearder">

<narBar :narBarValue="header"></narBar>

</div>

<div class="good-nav" :style="{opacity:opacity}">

<div class="good-nav-title">

<nav class="good-nav-title-detail">

<a @click="onScrollGoods" href="javascript:" :class="{'active':active=='goods'}">商品</a>

<a @click="onScrollDetail" href="javascript:" :class="{'active':active=='detail'}">詳情</a>

<a @click="onScrollEvaluation" href="javascript:" :class="{'active':active=='evaluation'}">評(píng)價(jià)</a>

</nav>

</div>

</div>


? ? <div class="good-swiper">

<swiper :imgList="images"></swiper>

</div>


? ? <div class="good-wrap">

<wrap :spuData="spuData"></wrap>

</div>

</div>

</template>

<script>

import narBarfrom "@/components/NavBar/index";

import swiperfrom "@/components/Swiper/index";

import wrapfrom "@/components/Wrap/index";

export default {

name:"index",

data() {

return {

// active: 1,

? ? ? header:"商品詳情",

imgList: [

{img: require("@/assets/img/good.jpg") },

{img: require("@/assets/img/good.jpg") },

{img: require("@/assets/img/good.jpg") },

{img: require("@/assets/img/good.jpg") }

],

spuData:"",

decript:"",//富文本編輯顯示的文字和圖片字段

? ? ? images: [],

/*下滑參數(shù)*/

? ? ? scrollTop:0,

opacity:0,

active:'goods',

};

},

components: {

narBar,

swiper,

wrap

},

created() {

//獲取詳情

? ? this.handleDetail();

},

mounted() {

window.addEventListener('scroll',this.handleScroll);

},

methods: {

handleScroll(){

let scrollTop =window.pageYOffset ||document.documentElement.scrollTop ||document.body.scrollTop;

if (scrollTop <200) {

// 當(dāng)滾動(dòng)距離小于200時(shí),計(jì)算導(dǎo)航透明度疑务,可以考慮修改為每20增加0.1

// this.opacity = (scrollTop / 200).toFixed(1);

? ? ? ? this.opacity =scrollTop /200;

this.active ='goods';

return

? ? ? }else {

this.opacity =1

? ? ? }

// 當(dāng)滾動(dòng)距離不小于200時(shí),獲取三個(gè)部分的頂部位置-46啼辣。

? ? ? let getDetail=document.getElementById('detail');

let getEvaluation=document.getElementById('evaluation');

let detail =getDetail.offsetTop -106;

let evaluation =getEvaluation.offsetTop -106;

// 計(jì)算滾動(dòng)距離在哪個(gè)區(qū)間,修改this.active對(duì)應(yīng)的樣式名

? ? ? if (scrollTop

else if (scrollTop >=detail &&scrollTop

else if (scrollTop >=evaluation) {if (this.active !='evaluation')this.active ='evaluation'; }

},

onScrollGoods(){

window.scrollTo({top:0,behavior:"smooth" });

},

onScrollDetail(){

let getDetail=document.getElementById('detail');

if (!this.opacity)return;

window.scrollTo({top:getDetail.offsetTop -106,behavior:"smooth" });

},

onScrollEvaluation(){

let getEvaluation=document.getElementById('evaluation');

if (!this.opacity)return;

window.scrollTo({top:getEvaluation.offsetTop -106,behavior:"smooth" });

},

//獲取詳情

? ? handleDetail() {

// 傳id或者spuId(*****)

? ? ? let url =`/mall/app/spu/detail?spuId=55`;

this.$get(url)

.then(({ data }) => {

if (data.code ==100000) {

// this.$toast.success('成功文案');

? ? ? ? ? ? console.log(data);

this.spuData = data.data.decript;

this.decript = data.data.decript;

this.images = data.data.images;

}

})

.catch(error => {

console.log(error);

});

}

}

};

</script>

<style lang="scss" scoped>

@import "@css/style.scss";

.good {

margin-top:46px;

background:$textBackgroundColors;

&-swiper {

width:100%;

background:$textSwiperColor;

}

&-nav {

z-index:99;

opacity:999;

position:fixed;

width:100%;

background:$textBackgroundColor;

min-height:px2rem(50);

height:px2rem(50);

&-title{

width:90%;

margin:0 auto;

&-detail{

a{

font-weight:500;

line-height:px2rem(20);

font-size:px2rem(14);

color:$textMoneyCourier;

margin-right:px2rem(50);

}

}

}

}

&-wrap {

width:100%;

}

}

</style>

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末躁绸,一起剝皮案震驚了整個(gè)濱河市辖佣,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌熬词,老刑警劉巖,帶你破解...
    沈念sama閱讀 218,546評(píng)論 6 507
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件吸重,死亡現(xiàn)場(chǎng)離奇詭異互拾,居然都是意外死亡,警方通過(guò)查閱死者的電腦和手機(jī)嚎幸,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,224評(píng)論 3 395
  • 文/潘曉璐 我一進(jìn)店門颜矿,熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái),“玉大人嫉晶,你說(shuō)我怎么就攤上這事骑疆。” “怎么了替废?”我有些...
    開封第一講書人閱讀 164,911評(píng)論 0 354
  • 文/不壞的土叔 我叫張陵箍铭,是天一觀的道長(zhǎng)。 經(jīng)常有香客問(wèn)我椎镣,道長(zhǎng)诈火,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 58,737評(píng)論 1 294
  • 正文 為了忘掉前任状答,我火速辦了婚禮冷守,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘惊科。我一直安慰自己拍摇,他們只是感情好,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,753評(píng)論 6 392
  • 文/花漫 我一把揭開白布馆截。 她就那樣靜靜地躺著授翻,像睡著了一般。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上堪唐,一...
    開封第一講書人閱讀 51,598評(píng)論 1 305
  • 那天,我揣著相機(jī)與錄音翎蹈,去河邊找鬼淮菠。 笑死,一個(gè)胖子當(dāng)著我的面吹牛荤堪,可吹牛的內(nèi)容都是我干的合陵。 我是一名探鬼主播,決...
    沈念sama閱讀 40,338評(píng)論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼澄阳,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼拥知!你這毒婦竟也來(lái)了?” 一聲冷哼從身側(cè)響起碎赢,我...
    開封第一講書人閱讀 39,249評(píng)論 0 276
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤低剔,失蹤者是張志新(化名)和其女友劉穎,沒想到半個(gè)月后肮塞,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體襟齿,經(jīng)...
    沈念sama閱讀 45,696評(píng)論 1 314
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,888評(píng)論 3 336
  • 正文 我和宋清朗相戀三年枕赵,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了猜欺。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點(diǎn)故事閱讀 40,013評(píng)論 1 348
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡拷窜,死狀恐怖开皿,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情篮昧,我是刑警寧澤赋荆,帶...
    沈念sama閱讀 35,731評(píng)論 5 346
  • 正文 年R本政府宣布,位于F島的核電站恋谭,受9級(jí)特大地震影響糠睡,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜疚颊,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,348評(píng)論 3 330
  • 文/蒙蒙 一狈孔、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧材义,春花似錦均抽、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,929評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)。三九已至,卻和暖如春深寥,著一層夾襖步出監(jiān)牢的瞬間攘乒,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 33,048評(píng)論 1 270
  • 我被黑心中介騙來(lái)泰國(guó)打工惋鹅, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留则酝,地道東北人。 一個(gè)月前我還...
    沈念sama閱讀 48,203評(píng)論 3 370
  • 正文 我出身青樓闰集,卻偏偏與公主長(zhǎng)得像沽讹,于是被迫代替她去往敵國(guó)和親。 傳聞我的和親對(duì)象是個(gè)殘疾皇子武鲁,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,960評(píng)論 2 355