当前位置: 首页 > wzjs >正文

唐河企业网站制作怎么样怎么用ps做网站首页

唐河企业网站制作怎么样,怎么用ps做网站首页,新平台推广赚钱,外包加工网站有哪些项目场景: 提示:这里简述项目相关背景: 在项目中有时候需要显示一些动态效果,但是如果页面过长刷新页面的时候有些效果在没看到的时候就会执行,那么能滚动到那个区域的时候哪些动态效果就在没看到的时候就已经执行过…

项目场景:

提示:这里简述项目相关背景:

在项目中有时候需要显示一些动态效果,但是如果页面过长刷新页面的时候有些效果在没看到的时候就会执行,那么能滚动到那个区域的时候哪些动态效果就在没看到的时候就已经执行过了,那怎么才能让后滚动到可视区域的时候才执行呢?

在Vue 3中,要判断一个元素是否到达可视区域,你可以使用几种不同的方法。最常见和直接的方法是利用Intersection Observer API

Intersection Observer是一个非常强大的API,可以自动“观察”目标元素是否进入其祖先元素或顶级文档视口的可见区域。

到达可视区域的时候就会执行


分析:

提示:这里填写问题的分析:

 首先需要时vue3项目,另外,要在onMounted钩子函数中作操作

基本操作如下

1:使用Intersection Observer

<template><div ref="observerElement" class="observed-element">我是需要观察的元素</div>
</template><script setup>
import { ref, onMounted } from 'vue';const observerElement = ref(null);onMounted(() => {const options = {root: null, // 使用视口作为参照点rootMargin: '0px',threshold: 0.1 // 元素10%在视口内时触发回调};const callback = (entries, observer) => {entries.forEach(entry => {if (entry.isIntersecting) {console.log('元素进入了视口!');} else {console.log('元素离开了视口。');}});};const observer = new IntersectionObserver(callback, options);if (observerElement.value) {observer.observe(observerElement.value);}
});
</script>

 2:计算元素位置与视口的关系

如果你不希望使用Intersection Observer API,你可以通过计算元素的位置来判断它是否进入视口。这通常涉及到获取元素的位置和视口的高度。

<template><div ref="element" class="observed-element">我是需要观察的元素</div>
</template><script setup>
import { ref, onMounted } from 'vue';const element = ref(null);onMounted(() => {const checkVisibility = () => {if (!element.value) return;const rect = element.value.getBoundingClientRect();const isVisible = (rect.top >= 0 &&rect.left >= 0 &&rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) &&rect.right <= (window.innerWidth || document.documentElement.clientWidth));if (isVisible) {console.log('元素进入了视口!');} else {console.log('元素离开了视口。');}};checkVisibility(); // 初始检查一次// 添加滚动事件监听器以持续检查window.addEventListener('scroll', checkVisibility); // 添加窗口大小改变事件监听器以持续检查window.addEventListener('resize', checkVisibility); 
});
</script>

方案实例:

提示:这里填写该问题的具体解决方案:

在组件中使用这个方法直接在子组件中使用不需要再父组件中操作

如下:

父组件:

<!-- 使用子组件 --><bannerGreen:bannerInfo="bannerInfo"/>//引入子组件
import bannerGreen from '@/view/Home/components/bannerGreen.vue';

子组件

<template><div ref="observerElement" class="observed-element flexEv bannerBg padTB100 padLR65 colorW"><div class="flex" v-for="item in props.bannerInfo"><div class="borderR paddingR20 flexC"><i :class="item.icon" class="iconfont fontS40 fontW4 colorW hoverS"></i></div><div class="paddingL20"><div ref="numRef" class="fontS26 fontW6 marginB10 number inLb":data-target="item.textTop"></div> <div class="fontS26 fontW6 inLb">+</div><div class="fontS18 fontW5">{{item.textBottom}}</div></div></div></div>
</template><script lang="ts" setup>
import {reactive,toRefs,ref,Ref,PropType,onMounted,onBeforeUnmount,
} from "vue"
const props=defineProps({// bannerInfo:{type:Array},
})
// 自动将数值加到会后那个值的方法
const changeNum=()=>{// 获取元素const numbers = document.querySelectorAll('.number')console.log("",numbers)// 获取所有的dom,querySelectorAll为为数组numbers.forEach(item => {item.textContent = "0";const upDateNumber = () => {// 获取每个类名为number的data-target,即获取最大值 const target = Number(item.getAttribute('data-target'))// 获取当前div的数值const d = Number(item.textContent)// 设置数据增加的值,可以通过target除的数值确定怎么加数值的快慢const increment = target / 100// 当数字小于最大值时,执行下面的操作if (d < target) {// 向上取整item.textContent = `${Math.ceil(d + increment)}`// 1ms重新调用,不然它会在第一次运行完就结束setTimeout(upDateNumber, 10)} else {item.textContent = target+"";//textContent的值是 字符串 所以加个空字符}}upDateNumber()})
}
onMounted(()=>{console.log()})
// ================================到达可视区域的方法
const observerElement = ref(null);
onMounted(() => {const options = {root: null, // 使用视口作为参照点rootMargin: '0px',threshold: 0.1 // 元素10%在视口内时触发回调};const callback = (entries:any, observer:any) => {entries.forEach((entry:any) => {if (entry.isIntersecting) {console.log('元素进入了视口!');//到达可视区域 执行 数字自增的方法changeNum()} else {console.log('元素离开了视口。');}});};const observer = new IntersectionObserver(callback, options);if (observerElement.value) {observer.observe(observerElement.value);}
});
onBeforeUnmount(()=>{console.log()
})
const emit =defineEmits([""
])</script><style lang="less" scoped>
.bannerBg{background-color:#1d7b51 ;
}
.borderR{border-right: 1px solid #ffffff;
}
</style>


文章转载自:

http://MbMpktMi.nwmwp.cn
http://hlwXirR5.nwmwp.cn
http://5vdDhqso.nwmwp.cn
http://23lKq9We.nwmwp.cn
http://erOW7MK0.nwmwp.cn
http://8m47lZh5.nwmwp.cn
http://AL5V6h5p.nwmwp.cn
http://XKulet8E.nwmwp.cn
http://qpzu4gsa.nwmwp.cn
http://Zj3qPzoR.nwmwp.cn
http://uX2epzY0.nwmwp.cn
http://hEit9Tn0.nwmwp.cn
http://3YGvFQNk.nwmwp.cn
http://49FfYm0b.nwmwp.cn
http://cJVHBLGR.nwmwp.cn
http://wbIW9VVR.nwmwp.cn
http://h0ewEoDt.nwmwp.cn
http://H2U0MIXG.nwmwp.cn
http://qsZOMHgI.nwmwp.cn
http://T864vbnY.nwmwp.cn
http://T4uWeG09.nwmwp.cn
http://05DLFj8P.nwmwp.cn
http://yn1wK1JM.nwmwp.cn
http://8EKIoXut.nwmwp.cn
http://Hw8BUnt9.nwmwp.cn
http://Rf0FV5Bb.nwmwp.cn
http://ItdL0r5V.nwmwp.cn
http://OCL0KtdL.nwmwp.cn
http://969R4FYk.nwmwp.cn
http://ZSbheB6Z.nwmwp.cn
http://www.dtcms.com/wzjs/655872.html

相关文章:

  • 北京住房与城乡建设厅网站首页miya1173跳转接口
  • 企业网站推广平台微信建网站服务
  • 遵义怎样做网站wordpress 后台 主题
  • 集团网站建设招标附近做广告牌的电话
  • 怎样做网站漂浮扬州做网站的
  • 杭州做网站hzyze深圳外贸建站网络推广哪家好
  • 网站列表怎么做东莞什么行业做网站的多
  • 无锡做网站公司哪家比较好python网站开发教程
  • 优秀设计师的个人网站买卖网站
  • 中山做网站网站建设备案条件
  • 苏州做网站哪里好wordpress 图片 筛选 插件
  • 网站建设实训的心得的体会访问自己做的网站
  • 网站响应式首页模板下载如何用flashfxp上传网站
  • 一 建设网站前的市场分析松原建设网站
  • 有哪里可以做兼职翻译的网站wordpress采集自动伪原创
  • 润滑油手机网站模板桂林公司注册
  • 做垂直导购网站还行吗苏州沧浪做网站哪家好
  • 博物馆网站建设国外搜索引擎大全
  • 自己做网站投放广告如何做行业网站
  • 南昌淘宝网站制作公司wordpress 微信连接数据库
  • 兰州网站维护地方网站怎么做推广
  • 公司网站图片传不上去wordpress在IE9显示错位
  • 北京p2p网站建设即速应用小程序官网
  • 创意设计网站公司医药行业网站建设
  • 怎么推广公司网站做直播导航网站
  • 石家庄市环保局网站建设项目备案系统wordpress 评论贴图
  • 做国外的营销的网站vr网站建设
  • 民治营销型网站上国外的网站很慢
  • 自己做的网页加在网站文章上为什么打不开游戏网站排行
  • 电子商务网站怎么做推广创意界面