您好,登錄后才能下訂單哦!
這篇文章主要講解了“怎么用vue實(shí)現(xiàn)內(nèi)容可滾動(dòng)的彈窗效果”,文中的講解內(nèi)容簡(jiǎn)單清晰,易于學(xué)習(xí)與理解,下面請(qǐng)大家跟著小編的思路慢慢深入,一起來研究和學(xué)習(xí)“怎么用vue實(shí)現(xiàn)內(nèi)容可滾動(dòng)的彈窗效果”吧!
本文實(shí)例為大家分享了vue實(shí)現(xiàn)內(nèi)容可滾動(dòng)的彈窗效果具體代碼,供大家參考,具體內(nèi)容如下
這是第一種實(shí)現(xiàn)方式
效果圖:
彈窗代碼:
Popup.vue
<template lang="html"> <div v-if="show" class="modal-bg" @click="closeModal"> <div class="modal_con"> <div class="modal_content"> <div class="modal-container"> <div class="modal_main"> <p class="modal-header">{{dataList.title}}</p> <div class="rules_text"> <p v-for="(item, index) in dataList.rules" class="rules_txt" :key="index" > {{ item }} </p> </div> </div> </div> <div class="footer_rules"> <div class="tips"></div> <div class="rules_button"> <div class="button" @click="closeModal"> <p class="button_text">我知道了</p> </div> </div> </div> </div> </div> </div> </template> <script> export default { name: 'Popup', props: { show: { type: Boolean, default: false }, }, data () { return { dataList: { rules: [ '1.這是第一條數(shù)據(jù)啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊', '2.這是第二條數(shù)據(jù)啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊', '3.這是第三條數(shù)據(jù)啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊', '4.這是第四條數(shù)據(jù)啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊' ], reward: [ '1.活動(dòng)規(guī)則第一條數(shù)據(jù)數(shù)據(jù)數(shù)據(jù)數(shù)據(jù)', '2.活動(dòng)規(guī)則第二條數(shù)據(jù)數(shù)據(jù)數(shù)據(jù)', '2.活動(dòng)規(guī)則第三條數(shù)據(jù)數(shù)據(jù)數(shù)據(jù)' ] } } }, methods: { closeModal () { this.$emit('closeModal') }, } } </script> <style lang="css" scoped> .modal_con { width: 80%; height: 287px; background: #ffffff; overflow: hidden; margin: 0 auto; position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); border-radius: 8px; } .modal_content { height: 100%; background-color: #fff; } .modal-bg { width: 100%; height: 100%; background-color: rgba(0, 0, 0, 0.6); position: fixed; top: 0; left: 0; z-index: 999; } .modal-container { height: 78%; text-align: center; display: flex; flex-direction: column; overflow-y: scroll; /* ios需要下面這個(gè)屬性 */ -webkit-overflow-scrolling: touch; } .rules_txt { font-size: 15px; font-family: PingFangSC, PingFangSC-Regular; font-weight: 400; text-align: justify; color: #666666; padding: 0 20px; margin-top: 8px; margin-bottom: 0; } .rules_txt:last-child { padding-bottom: 40px; } .modal-header { font-size: 17px; font-family: PingFang, PingFang-SC; font-weight: bold; text-align: center; color: #333333; margin: 0; padding-top: 20px; } .reward_title { font-size: 17px; font-family: PingFang, PingFang-SC; font-weight: bold; text-align: center; color: #333333; padding: 0; margin-top: 14px; margin-bottom: 6px; } .footer_rules { width: 100%; height: 22%; position: absolute; bottom: 0; } .tips { /* width: 100%; opacity: 0.6; height: 49px; background: linear-gradient(180deg, rgba(255, 255, 255, 0.5), #ffffff); text-align: center; line-height: 49px; font-size: 18px; */ } .rules_button { width: 100%; background: #ffffff; padding-bottom: 20px; border-bottom-right-radius: 8px; border-bottom-left-radius: 8px; } .button { width: 90%; display: flex; justify-content: center; align-content: center; background: linear-gradient(270deg, #1283ff, #50a3ff); border-radius: 4px; text-align: center; margin: 0 auto; } .button_text { font-size: 15px; font-family: PingFang, PingFang-SC; font-weight: SC; color: #ffffff; display: flex; justify-content: center; align-content: center; margin: 0; padding: 12px 0; } .rules_con { padding-bottom: 80px; } </style>
在Home.vue頁面使用彈窗:
<!-- 活動(dòng)規(guī)則彈窗 --> <template> <div> <div @click="clickPopup"> <span>點(diǎn)擊彈出彈窗</span> </div> <Popup v-show="isRulesShow" @closeModal="isRulesShow = false" :show="isRulesShow" > </Popup> </div> </template> <script> import Popup from './Popup' export default { name:"Home", components: { Popup }, data () { return { isRulesShow:flase } }, watch: { isRulesShow (v) { if (v) { //禁止主頁面滑動(dòng)方法在main.js this.noScroll() } else { //主頁面可滑動(dòng) this.canScroll() } }, }, methods:{ //活動(dòng)規(guī)則彈窗 clickPopup () { this.isRulesShow = true }, } } </script> <style lang="scss" scoped> * { touch-action: pan-y; } </style>
解決彈窗滾動(dòng),里面的body也跟著滾動(dòng)問題
在main.js中
//彈出框禁止滑動(dòng) Vue.prototype.noScroll = function () { var mo = function (e) { e.preventDefault() } document.body.style.overflow = 'hidden' document.addEventListener('touchmove', mo, false,{ passive: false })// 禁止頁面滑動(dòng) } //彈出框可以滑動(dòng) Vue.prototype.canScroll = function () { var mo = function (e) { e.preventDefault() } document.body.style.overflow = ''// 出現(xiàn)滾動(dòng)條 document.removeEventListener('touchmove', mo, false,{ passive: false }) }
在頁面使用時(shí):
//禁止主頁面滑動(dòng) this.noScroll() //主頁面可滑動(dòng) this.canScroll() //還要加上樣式: * { touch-action: pan-y; }
感謝各位的閱讀,以上就是“怎么用vue實(shí)現(xiàn)內(nèi)容可滾動(dòng)的彈窗效果”的內(nèi)容了,經(jīng)過本文的學(xué)習(xí)后,相信大家對(duì)怎么用vue實(shí)現(xiàn)內(nèi)容可滾動(dòng)的彈窗效果這一問題有了更深刻的體會(huì),具體使用情況還需要大家實(shí)踐驗(yàn)證。這里是億速云,小編將為大家推送更多相關(guān)知識(shí)點(diǎn)的文章,歡迎關(guān)注!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。