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

烟台网站建设策划99作文网

烟台网站建设策划,99作文网,百度公司招聘2022年最新招聘,直播开放平台登录文章目录 需求分析1. 创建公告组件Notice.vue2. 注册全局组件3. 使用 需求 系统中需要有一个公告展示#xff0c;且这个公告位于页面上方#xff0c;每个页面都要看到 分析 1. 创建公告组件Notice.vue 第一种 在你的项目的合适组件目录下#xff08;比如components目录且这个公告位于页面上方每个页面都要看到 分析 1. 创建公告组件Notice.vue 第一种 在你的项目的合适组件目录下比如components目录创建Notice.vue文件内容如下 templatediv classnotice-bar-containerdiv classnotice-bar v-ifshowNoticediv classnotice-content-wrapperdiv classnotice-content refnoticeContentspan v-ifisScrolling{{ noticeText }}/span/div/divbutton classclose-btn clickcloseNotice×/button/div/div /templatescript setup import { ref, onMounted, nextTick, onBeforeMount } from vue; import { onMounted as onWindowMounted } from vue/runtime-core;// 控制公告栏是否显示的响应式变量 const showNotice ref(true); // 公告内容 const noticeText ref(这里是公告内容示例可替换哦); const noticeContent ref(null); // 用于存储页面宽度 const pageWidth ref(window.innerWidth); // 用来存储滚动定时器 const scrollInterval ref(null); // 控制公告内容是否开始滚动展示的变量 const isScrolling ref(false);// 关闭公告的方法 const closeNotice () {showNotice.value false;if (scrollInterval.value) {clearInterval(scrollInterval.value);} };// 在组件挂载前获取页面宽度首次 onBeforeMount(() {pageWidth.value window.innerWidth; });// 当窗口大小变化时更新页面宽度 onWindowMounted(() {window.addEventListener(resize, () {pageWidth.value window.innerWidth;}); });onMounted(() {nextTick(() {// 获取滚动内容的宽度const contentWidth noticeContent.value.offsetWidth;// 设置外层容器宽度为页面宽度的50%并开启滚动noticeContent.value.parentNode.parentNode.style.width ${pageWidth.value * 0.5}px;noticeContent.value.parentNode.parentNode.style.marginLeft auto;noticeContent.value.parentNode.parentNode.style.marginRight auto;noticeContent.value.parentNode.parentNode.style.overflow hidden;// 克隆一份内容用于滚动衔接const cloneNode noticeContent.value.cloneNode(true);noticeContent.value.parentNode.appendChild(cloneNode);// 滚动动画逻辑let scrollDistance pageWidth.value * 0.5;const scrollSpeed 2; // 调整滚动速度可按需修改scrollInterval.value setInterval(() {scrollDistance - scrollSpeed;if (scrollDistance -contentWidth) {scrollDistance pageWidth.value * 0.5;}noticeContent.value.style.transform translateX(${scrollDistance}px);// 隐藏页面展示的文字只展示滚动的文字noticeContent.value.parentNode.style.overflow hidden;// 清除公告内容区域可能存在的文本节点除了绑定的 noticeText 内容const childNodes noticeContent.value.childNodes;for (let i 0; i childNodes.length; i) {if (childNodes[i].nodeType 3 childNodes[i].textContent.trim()! noticeText.value.trim()) {noticeContent.value.removeChild(childNodes[i]);}}// 开始滚动时设置 isScrolling 为 true展示公告内容isScrolling.value true;}, 30);}); }); /scriptstyle scoped .notice-bar-container {width: 100%;display: flex;justify-content: center; } .notice-bar {position: fixed;top: 0;background-color: #f8d7da;color: #721c24;padding: 10px;display: flex;justify-content: space-between;align-items: center;z-index: 999; } .notice-content-wrapper {flex: 1;overflow: hidden; } .notice-content {white-space: nowrap;display: inline-block; } .close-btn {background-color: transparent;border: none;color: inherit;font-size: 16px;cursor: pointer; } /style亮点 通过showNotice这个ref来控制公告栏是否显示初始化为true表示默认显示。 noticeText用来存放公告的具体文本内容这里提供了一个示例文本实际使用时可以替换成真实的公告内容来源比如从接口获取等。closeNotice方法用于点击关闭按钮时隐藏公告栏即将showNotice设置为false。 样式部分设置公告栏为固定定位在页面顶部设置了合适的背景色、文字颜色、内边距等并且让关闭按钮靠右对齐同时给了较高的z-index值确保它能显示在页面上方。 第二种 templatediv v-ifvisible classannouncement-containerdiv classannouncement-content :style{ width: contentWidth px }span{{ message }}/span/divbutton classclose-btn clickcloseAnnouncementx/button/div /templatescript setup import { ref, onMounted } from vue;const visible ref(true); // 公告是否显示 const message ref(这是一条滚动公告您可以设置任何内容显示在这里。); const contentWidth ref(0); // 动态计算公告内容的宽度// 页面加载时计算公告的宽度 onMounted(() {contentWidth.value window.innerWidth / 2; // 公告宽度为页面宽度的50% });// 关闭公告的逻辑 const closeAnnouncement () {visible.value false; };/scriptstyle scoped .announcement-container {position: fixed;top: 22%;left: 50%;transform: translateX(-50%);width: 50%;background-color: #ff9800;color: white;padding: 10px;display: flex;justify-content: space-between;align-items: center;z-index: 9999;font-size: 16px;border-radius: 5px;overflow: hidden; }.announcement-content {white-space: nowrap;overflow: hidden;animation: scroll-left 20s linear infinite; }keyframes scroll-left {0% {transform: translateX(100%);}100% {transform: translateX(-100%);} }.close-btn {background: transparent;border: none;color: white;font-size: 20px;cursor: pointer;padding: 5px;margin-left: 10px; } /style 2. 注册全局组件 在你的项目的入口文件比如main.js或者main.ts如果是 Vue 3 TypeScript 的话中进行全局组件注册示例如下 import { createApp } from vue; import App from ./App.vue; import Notice from ./components/Notice.vue;const app createApp(App); // 注册全局公告组件 app.component(Notice, Notice); app.mount(#app);通过app.component方法将Notice组件注册为全局组件这样在项目的任何页面组件中都可以直接使用标签来展示公告栏了。 3. 使用 例如在App.vue或者其他页面组件中使用 templatediv idappNotice /router-view/router-view/div /template
http://www.zqtcl.cn/news/280094/

相关文章:

  • 桂城网站制作公司wordpress 导航网站
  • 一个公司做网站需要注意什么条件网站备案 登陆
  • 百度网站介绍显示图片装修公司一般多少钱一平方
  • 网站销售如何做业绩我找伟宏篷布我做的事ko家的网站
  • 建立网站有哪些步骤?jsp网站开发详细教程
  • 网站怎么做直播功能旅游做攻略用什么网站
  • 企业外贸营销型网站如何写好软文推广
  • 免费建站的网址个人网站建设程序设计
  • 淘宝网站建设违规吗上海大公司
  • 大淘客怎么自己做网站自己开网站能赚钱吗
  • 大型门户网站开发北京网站建设管庄
  • 大连建设工程网站网站建设组织管理怎么写
  • wordpress英文站注册域名需要注意什么
  • 营销型网站的建设重点是什么深圳logo设计公司排名
  • 做网站的用什么软件呢网站排名优化服务公司
  • 网站开发完整视频网站集约化建设较好的城市
  • 网站建设和平面设计应用网站如何做
  • 自己做网站需要多少费用asa8.4 做网站映射
  • 商业网站 模板黑龙江省建设厅安全员考试
  • 网站新备案不能访问室内装修网站模板
  • 工程师报考网站wordpress设置视频图片不显示图片
  • 徐州网站建设公司排名成都住建平台
  • 用来备案企业网站国外免费外贸网站
  • 网页背景做的比较好的网站做一个企业网站价格
  • 免费制图网站县级门户网站建设的报告
  • 北京网站建设网怎么用手机做一个网站
  • 网站建设管理办法关于公司门户网站建设的议案
  • 网站开发入职转正申请书体验好的网站
  • 在线精品课程网站开发网站备案号怎么修改
  • 网站建设 风险百度热搜的含义