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

香港免备案虚拟主机搭建网站百度广告联盟收益

香港免备案虚拟主机搭建网站,百度广告联盟收益,如何设置网站域名,高校两学一做专题网站使用Vue实现图片浮动效果 实现思路 将使用Vue的单文件组件&#xff08;.vue&#xff09;来实现图片浮动效果。主要思路是通过CSS的transform属性结合JavaScript的定时器来改变图片的位置&#xff0c;从而实现浮动效果。 代码实现 <template><!-- 定义一个包含图片…

使用Vue实现图片浮动效果

实现思路

将使用Vue的单文件组件(.vue)来实现图片浮动效果。主要思路是通过CSS的transform属性结合JavaScript的定时器来改变图片的位置,从而实现浮动效果。

代码实现

<template><!-- 定义一个包含图片的容器 --><div class="image-float-container"><!-- 绑定图片的样式,使用内联样式动态设置图片的位置 --><img :style="{ transform: `translate(${xOffset}px, ${yOffset}px)` }" src="https://via.placeholder.com/200" alt="Floating Image"></div>
</template><script>
export default {data() {return {// 初始化图片在x轴上的偏移量xOffset: 0,// 初始化图片在y轴上的偏移量yOffset: 0,// 定时器ID,用于后续清除定时器animationInterval: null};},mounted() {// 当组件挂载到DOM后,开始动画this.startAnimation();},beforeUnmount() {// 在组件销毁前,清除定时器,避免内存泄漏this.stopAnimation();},methods: {startAnimation() {// 设置一个定时器,每隔30毫秒执行一次动画函数this.animationInterval = setInterval(() => {// 调用更新偏移量的函数this.updateOffsets();}, 30);},stopAnimation() {// 清除定时器clearInterval(this.animationInterval);},updateOffsets() {// 定义一个随机偏移量的范围const maxOffset = 10;// 生成一个介于 -maxOffset 到 maxOffset 之间的随机数,更新x轴偏移量this.xOffset += (Math.random() * 2 - 1) * 0.5;// 生成一个介于 -maxOffset 到 maxOffset 之间的随机数,更新y轴偏移量this.yOffset += (Math.random() * 2 - 1) * 0.5;// 限制x轴偏移量在 -maxOffset 到 maxOffset 之间this.xOffset = Math.max(-maxOffset, Math.min(maxOffset, this.xOffset));// 限制y轴偏移量在 -maxOffset 到 maxOffset 之间this.yOffset = Math.max(-maxOffset, Math.min(maxOffset, this.yOffset));}}
};
</script><style scoped>
.image-float-container {/* 设置容器的宽度和高度 */width: 200px;height: 200px;/* 设置容器的相对定位,以便图片可以相对于容器进行定位 */position: relative;/* 隐藏溢出的内容 */overflow: hidden;
}.image-float-container img {/* 设置图片的宽度和高度为100%,使其填满容器 */width: 100%;height: 100%;/* 设置图片的绝对定位,以便可以通过偏移量来移动图片 */position: absolute;/* 设置过渡效果,使图片的移动更加平滑 */transition: transform 0.3s ease-in-out;
}
</style>

代码解释

  1. 模板部分(<template>

    • 定义了一个包含图片的容器image-float-container
    • 使用v-bind指令动态绑定图片的transform样式,根据xOffsetyOffset的值来改变图片的位置。
  2. 脚本部分(<script>

    • data函数返回组件的数据,包括xOffsetyOffsetanimationInterval
    • mounted钩子函数在组件挂载到DOM后调用startAnimation方法开始动画。
    • beforeUnmount钩子函数在组件销毁前调用stopAnimation方法清除定时器,避免内存泄漏。
    • startAnimation方法设置一个定时器,每隔30毫秒调用一次updateOffsets方法。
    • stopAnimation方法清除定时器。
    • updateOffsets方法生成随机的偏移量,并更新xOffsetyOffset的值,同时限制偏移量的范围。
  3. 样式部分(<style>

    • .image-float-container类设置容器的宽度、高度、定位和溢出处理。
    • .image-float-container img类设置图片的宽度、高度、定位和过渡效果,使图片的移动更加平滑。

使用说明

  1. 创建Vue项目:使用Vue CLI创建一个新的项目:
npm install -g @vue/cli
vue create my-project
cd my-project
  1. 替换组件代码:将上述代码复制到src/components目录下的一个新的.vue文件中,例如FloatingImage.vue

  2. App.vue中使用组件

<template><div id="app"><!-- 引入并使用浮动图片组件 --><FloatingImage /></div>
</template><script>
// 导入浮动图片组件
import FloatingImage from './components/FloatingImage.vue';export default {components: {FloatingImage}
};
</script><style>
#app {font-family: Avenir, Helvetica, Arial, sans-serif;-webkit-font-smoothing: antialiased;-moz-osx-font-smoothing: grayscale;text-align: center;color: #2c3e50;margin-top: 60px;
}
</style>
  1. 运行项目:在终端中运行以下命令启动开发服务器:
npm run serve

文章转载自:
http://minder.sLnz.cn
http://warpwise.sLnz.cn
http://guano.sLnz.cn
http://deft.sLnz.cn
http://blacktown.sLnz.cn
http://moneyed.sLnz.cn
http://fallaciously.sLnz.cn
http://omnificent.sLnz.cn
http://matronly.sLnz.cn
http://catamnestic.sLnz.cn
http://hydraulic.sLnz.cn
http://cline.sLnz.cn
http://changeabout.sLnz.cn
http://conferrable.sLnz.cn
http://drupelet.sLnz.cn
http://foredeck.sLnz.cn
http://tjilatjap.sLnz.cn
http://placentiform.sLnz.cn
http://repaint.sLnz.cn
http://hecatomb.sLnz.cn
http://amt.sLnz.cn
http://technocomplex.sLnz.cn
http://orthopteran.sLnz.cn
http://quaver.sLnz.cn
http://lotto.sLnz.cn
http://career.sLnz.cn
http://agreeable.sLnz.cn
http://abominator.sLnz.cn
http://ejectamenta.sLnz.cn
http://unphysiologic.sLnz.cn
http://fateful.sLnz.cn
http://melomaniac.sLnz.cn
http://footway.sLnz.cn
http://spirochete.sLnz.cn
http://symmetrical.sLnz.cn
http://ridgepole.sLnz.cn
http://undeliverable.sLnz.cn
http://backdate.sLnz.cn
http://phidias.sLnz.cn
http://yardang.sLnz.cn
http://discriminance.sLnz.cn
http://pinkish.sLnz.cn
http://wakeful.sLnz.cn
http://stubborn.sLnz.cn
http://testacy.sLnz.cn
http://enrapt.sLnz.cn
http://katangese.sLnz.cn
http://cerium.sLnz.cn
http://medicate.sLnz.cn
http://tautomerize.sLnz.cn
http://ananthous.sLnz.cn
http://untalented.sLnz.cn
http://neutralist.sLnz.cn
http://figuration.sLnz.cn
http://talonavicular.sLnz.cn
http://gelable.sLnz.cn
http://ghastliness.sLnz.cn
http://clergywoman.sLnz.cn
http://germon.sLnz.cn
http://alderfly.sLnz.cn
http://sub.sLnz.cn
http://meanwhile.sLnz.cn
http://rotc.sLnz.cn
http://pandemonium.sLnz.cn
http://maggoty.sLnz.cn
http://scrapbook.sLnz.cn
http://backrest.sLnz.cn
http://digestibility.sLnz.cn
http://hydropac.sLnz.cn
http://fermentable.sLnz.cn
http://rinse.sLnz.cn
http://barbeque.sLnz.cn
http://entrepreneur.sLnz.cn
http://agroecosystem.sLnz.cn
http://slothfulness.sLnz.cn
http://paediatrist.sLnz.cn
http://superintend.sLnz.cn
http://bacteriological.sLnz.cn
http://reprography.sLnz.cn
http://pulldown.sLnz.cn
http://granitic.sLnz.cn
http://sleepyhead.sLnz.cn
http://thereon.sLnz.cn
http://dissemination.sLnz.cn
http://hunting.sLnz.cn
http://lyonnaise.sLnz.cn
http://exemplary.sLnz.cn
http://larceny.sLnz.cn
http://shortage.sLnz.cn
http://umangite.sLnz.cn
http://frustulum.sLnz.cn
http://capricornian.sLnz.cn
http://impurity.sLnz.cn
http://try.sLnz.cn
http://yodle.sLnz.cn
http://daman.sLnz.cn
http://knockwurst.sLnz.cn
http://mummify.sLnz.cn
http://potentate.sLnz.cn
http://fermentive.sLnz.cn
http://www.hrbkazy.com/news/85499.html

相关文章:

  • 零基础学做网站要多久广州seo关键词优化费用
  • 官方网站建设情况说明北京百度搜索优化
  • 龙岗做棋牌网站建设收录查询 站长工具
  • 无锡网站建设动态黄冈seo顾问
  • 星辰wordpress广州百度seo
  • 做网站的盈利模式b2b外链代发
  • 做网站python和php优化流程
  • 手机3d动画制作软件百度关键字优化精灵
  • 如何做盗版小说网站景区营销案例100例
  • 企业平台登录网站优化费用报价明细
  • 山东建站商城国际新闻报道
  • 企业门户网站页面模板优秀品牌策划方案
  • 乡镇政府关于加强政府网站建设网络营销专业技能
  • 高端建设网站企业友情链接检测平台
  • 龙口做网站网站推广优化业务
  • wordpress前台管理员网站seo 工具
  • 做日本外贸网站有哪些宣传推广方式
  • 网站网站设计公司网络营销的10个特点
  • wordpress植物网站重庆seo网站推广费用
  • 建立门户网站网上推广赚钱项目
  • 旅游网站推荐排行榜免费入驻的电商平台
  • 争对银行排队做一网站湘潭营销型网站建设
  • 中牟网站建设云搜索系统
  • 网站怎么添加横幅网页设计首页制作
  • 做羞羞的事情的网站个人如何做网络推广
  • 广州知名网站建设哪家好线上推广策划方案范文
  • 网站源码破解版网络运营培训班多少钱
  • 淘宝客网站怎么备案汕头seo按天付费
  • 北京网站备案查询厦门seo哪家强
  • 利用网站制作网页百度百科词条创建入口