vue中使用jquery滑動(dòng)到頁(yè)面底部的實(shí)現(xiàn)方式
使用jquery滑動(dòng)到頁(yè)面底部
期望點(diǎn)擊按鈕或其他操作時(shí)可以滾動(dòng)到底部
方法
?// 滑動(dòng)到底部
? ? scrollToBottom(){
? ? ? this.$nextTick(() => {
? ? ? ? ? ?//要滑動(dòng)的高度= 當(dāng)前dom的滑動(dòng)高度 - 當(dāng)前窗口可視區(qū)域高度
? ? ? ? ? ?var height = $("#scrollBox")[0].scrollHeight - $(window).height();
? ? ? ? ? ? $("#scrollBox").scrollTop(height); // 滑動(dòng)
? ? ? });
? ? }完整代碼
<template> ? <div id="scrollBox"> //有滾動(dòng)的dom ? ?? ?<div @click="scrollToBottom">點(diǎn)擊滑動(dòng)到底部</div> ? ? <div style="height:1500px;background:pink;">內(nèi)容高1500</div> ? </div> </template>
<script>
import $ from "jquery";
export default {
?data(){
? ? return{}
?},
?methods:{
? ? // 滑動(dòng)到底部
? ? scrollToBottom(){
? ? ? this.$nextTick(() => {
? ? ? ? ? ?//要滑動(dòng)的高度= 當(dāng)前dom的滑動(dòng)高度 - 當(dāng)前窗口可視區(qū)域高度
? ? ? ? ? ?var height = $("#scrollBox")[0].scrollHeight - $(window).height();
? ? ? ? ? ? $("#scrollBox").scrollTop(height); // 滑動(dòng)
? ? ? });
? ? }
? }
}
</script><style>
? #scrollBox { //有滾動(dòng)的dom
?? ?height: 100vh;
? ? overflow-y: auto;
? }
</style>vue使用jQuery,實(shí)現(xiàn)頁(yè)面到達(dá)指定位置時(shí)實(shí)現(xiàn)animate動(dòng)畫
vue中使用jquery
1、首先下載
npm install jquery -s
2、在項(xiàng)目根目錄下的build目錄下找到webpack.base.conf.js文件,在開(kāi)頭使用以下代碼引入webpack,因?yàn)樵撐募J(rèn)沒(méi)有引用。
var webpack = require('webpack')3、最后在build目錄下的webpack.base.conf.js文件里找到module.exports,添加以下代碼
plugins: [
new webpack.ProvidePlugin({
$: "jquery",
jQuery: "jquery",
jquery: "jquery",
"window.jQuery": "jquery"
})
],具體位置如圖:

記得重啟項(xiàng)目哦
實(shí)現(xiàn)頁(yè)面到達(dá)指定位置時(shí)實(shí)現(xiàn)animate動(dòng)畫
1、使用動(dòng)畫要先下載動(dòng)畫
npm install animate.css --save
2、在main.js中引入
import animated from 'animate.css/animate.css' Vue.use(animated);
3、在需要做動(dòng)畫的地方
<template>
? <div>
? ? <div class="head"><div>
? </div>
</template><script>
export default {
? ?data(){
? ? ?return {
? ? ?}
? },
? mounted(){
? ? $(window).scroll(function(){
? ? //這里100代表你要?jiǎng)赢嫷脑仉x最頂層的距離,console.log一下就知道了。
? ? ? ?if($(window).scrollTop() > 100){
? ? ? ? ? $('.head').addClass('animate__animated animate__bounce')
? ? ? ?}else{
? ? ? ? ? $('.head').removeClass('animate__animated animate__bounce')
? ? ? ?}
? ? })
}
</script>附上查看動(dòng)畫的網(wǎng)址:https://animate.style/
總結(jié)
以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
Vue使用v-viewer插件實(shí)現(xiàn)圖片預(yù)覽和縮放和旋轉(zhuǎn)等功能(推薦)
v-viewer是一個(gè)基于viewerjs封裝的vue圖片預(yù)覽組件,有預(yù)覽縮放拉伸旋轉(zhuǎn)切換拖拽等功能,支持配置化,這篇文章主要介紹了Vue使用v-viewer插件實(shí)現(xiàn)圖片預(yù)覽和縮放和旋轉(zhuǎn)等功能,需要的朋友可以參考下2023-02-02
element-ui+vue-treeselect下拉框的校驗(yàn)過(guò)程
這篇文章主要介紹了element-ui+vue-treeselect下拉框的校驗(yàn)過(guò)程,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-07-07
vue composition-api 封裝組合式函數(shù)的操作方法
在 Vue 應(yīng)用的概念中,“組合式函數(shù)”(Composables) 是一個(gè)利用 Vue 的組合式 API 來(lái)封裝和復(fù)用有狀態(tài)邏輯的函數(shù),這篇文章主要介紹了vue composition-api 封裝組合式函數(shù)的操作方法,需要的朋友可以參考下2022-10-10
解決Vue使用百度地圖BMapGL內(nèi)存泄漏問(wèn)題?Out?of?Memory
這篇文章主要介紹了解決Vue使用百度地圖BMapGL內(nèi)存泄漏問(wèn)題?Out?of?Memory,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-12-12
解決echarts vue數(shù)據(jù)更新,視圖不更新問(wèn)題(echarts嵌在vue彈框中)
這篇文章主要介紹了解決echarts vue數(shù)據(jù)更新,視圖不更新問(wèn)題(echarts嵌在vue彈框中),具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2020-07-07

