活动介绍
file-type

响应式页面布局的JavaScript侧边栏标签实现

ZIP文件

下载需积分: 5 | 904KB | 更新于2025-08-10 | 58 浏览量 | 0 下载量 举报 收藏
download 立即下载
### 知识点详细说明: #### 1. 从.psd创建响应页面布局 - **Photoshop文件(.psd)的理解和使用**:Photoshop是Adobe公司开发的图像编辑软件,常被用于设计网站界面的布局。设计师会通过.psd文件提供网页的视觉设计稿。理解这种文件格式是前端开发者在将设计转换为实际网页时的重要步骤。 - **响应式布局设计**:随着设备多样性的增加,网页需要对不同屏幕尺寸的设备友好展示,这就需要使用响应式设计。响应式设计可以通过使用媒体查询、流式布局、弹性图片等技术实现,以确保网站在各种设备上都能保持良好的可用性和用户体验。 #### 2. 脚本创建 - **JavaScript基础**:JavaScript是一种脚本语言,用于网页交互式的逻辑编程。在这个任务中,需要使用JavaScript来控制标签页的行为。 - **无库依赖脚本编写**:提到“没有任何库”,意味着将从基础出发,不使用如jQuery或Prototype这样的常见JavaScript库。这要求开发者熟悉原生JavaScript的各种对象和方法。 - **URL哈希处理**:哈希(即URL中#后面的部分)常用于前端框架中处理单页应用(SPA)的路由。在这个任务中,JavaScript需要处理URL的哈希部分,实现标签页的切换。 #### 3. URL哈希功能 - **哈希值解析**:页面加载时,通过JavaScript获取当前URL的哈希值,如果没有哈希值,则根据当前的标签页状态自动添加。 - **哈希值修改**:用户切换标签页时,需要动态改变URL的哈希值来反映当前激活的标签页。 - **自动添加默认哈希值**:如果URL没有哈希值,脚本需要自动添加默认的哈希值,例如将默认标签设置为“general”。 #### 4. 活动标签的动态展示 - **检测哈希值变化**:在页面加载时和用户交互过程中,需要实时检测URL的哈希值变化,并将其与当前的标签页状态对应。 - **动态切换活动标签**:根据哈希值,脚本需要控制哪个标签页是活动的。比如,当URL为example.com/#additional时,需要将“Additional”标签设置为激活状态。 #### 5. 适用于现代浏览器的兼容性 - **IE10之后的浏览器兼容性**:IE10发布于2013年,现在已经有了更新的浏览器版本。需要使用现代JavaScript技术,同时注意兼容性,以确保在IE10之后的现代浏览器中运行良好。 #### 6. 相关技术知识 - **DOM操作**:文档对象模型(DOM)是HTML和XML文档的编程接口,JavaScript通过DOM可以与页面结构进行交互。操作DOM元素是实现标签页切换等交互功能的基础。 - **事件处理**:事件是用户或浏览器自身执行的某些操作的信号。事件处理程序是响应这些事件的函数。在这个任务中,需要处理哈希值变化事件等。 - **URL解析和生成**:JavaScript提供了window.location对象,可以获取和设置URL的各个组成部分,包括哈希值。了解该对象的使用对于实现任务要求至关重要。 #### 7. 代码实现 - **JavaScript代码结构**:代码应该清晰组织,包括获取当前哈希值的函数、切换标签页的函数、添加事件监听器来响应哈希变化等。 - **错误处理和边界情况**:在编写代码时,还需要考虑到错误处理和边界情况,比如非标准的URL、浏览器不支持的特性等。 #### 8. 实际应用和测试 - **跨浏览器测试**:由于要求在IE10之后的浏览器中运行,需要进行跨浏览器测试,确保所有主流浏览器都能正确运行脚本。 - **响应式布局适配测试**:需要确保响应式布局在不同设备和屏幕尺寸上均能正确显示。 #### 9. 关键代码片段示例(伪代码) ```javascript // 获取当前URL的哈希值 function getHash() { return window.location.hash.substring(1); } // 设置哈希值 function setHash(hash) { window.location.hash = hash; } // 切换标签页的函数 function switchTab(hashValue) { // 模拟页面上标签页切换的逻辑 } // 监听哈希变化事件 window.addEventListener('hashchange', function() { switchTab(getHash()); }); // 页面加载时检查哈希值,并进行相应的处理 (function() { var currentHash = getHash(); if (!currentHash) { // 添加默认哈希值 setHash('general'); currentHash = 'general'; } switchTab(currentHash); })(); ``` 上述代码片段展示了处理哈希值和切换标签页的基本逻辑。需要注意的是,实际代码应该包含更详细的处理过程,包括页面上DOM元素的选择、样式变更、事件绑定等。实际项目中,还需要根据具体的设计和功能需求来详细实现每一个步骤。

相关推荐

filetype

<template> </template> <script> import UpdatePassword from './main-navbar-update-password' import { clearLoginInfo,EventBus } from '@/utils' import Router from 'vue-router' import http from '@/utils/httpRequest' import { isURL } from '@/utils/validate' export default { data () { return { firstLogin: true, updatePassowrdVisible: false, activeMenu: 'tradition' // 默认激活的菜单项ID } }, components: { UpdatePassword }, computed: { navbarLayoutType: { get () { return this.$store.state.common.navbarLayoutType } }, sidebarFold: { get () { return this.$store.state.common.sidebarFold }, set (val) { this.$store.commit('common/updateSidebarFold', val) } }, mainTabs: { get () { return this.$store.state.common.mainTabs }, set (val) { this.$store.commit('common/updateMainTabs', val) } }, menuActiveName: { get () { return this.$store.state.common.menuActiveName }, set (val) { this.$store.commit('common/updateMenuActiveName', val) } }, userName: { get () { return this.$store.state.user.name } }, isHomePage(){ return this.$route.path === '/home' }, // 左侧菜单显示 sidebarIsShow: { get () { return this.$store.state.common.sidebarIsShow }, set (val) { this.$store.commit('common/updateSidebarIsShow', val) } }, // 顶部菜单的点击 // activeMenuIndex() { // return this.activeMenu.toString(); // 转换为字符串,以匹配模板中的index // } }, created() { // 刚登录进来,多点击监控中心,防止左侧缓存的菜单出现---20241217 this.firstLogin && ---------------------------------- if(localStorage.getItem('firstLogin')===null){ localStorage.clear(); console.log('本地存储已清除'); localStorage.setItem('firstLogin', '1'); this.firstLogin = false; // alert('第一次进来,firstLogin='+localStorage.getItem('firstLogin')) // 显示左侧菜单隐藏 this.openHomeHandle () setTimeout(() => { // alert('延时加载') this.openHomeHandle (); }, 1); setTimeout(() => { // alert('延时加载') this.openHomeHandle (); }, 100); }else{ // 显示左侧菜单显示 // alert('firstLogin='+localStorage.getItem('firstLogin')) // this.$store.state.common.sidebarIsShow = true } //------------------------------------------------------------------------------------------------------------ this.openHomeHandle () setTimeout(() => { // alert('延时加载') this.openHomeHandle (); }, 10); setTimeout(() => { // alert('延时加载') this.openHomeHandle (); }, 100); setTimeout(() => { // alert('延时加载') this.openHomeHandle (); }, 120); setTimeout(() => { // alert('延时加载') this.openHomeHandle (); }, 180); // 页面加载时尝试恢复之前的选中状态。刷新时一直保持点击颜色 this.activeMenu = sessionStorage.getItem('activeMenu') || this.activeMenu; }, methods: { handleSelect(key, keyPath) { // 菜单项被点击时保存选中状态 sessionStorage.setItem('activeMenu', key); // vue刷新页面数据不丢失-localStorage或sessionStorage保存数据 }, openEchartInNewWindow() { const routeData = this.$router.resolve({ name: 'echart' }); window.open(routeData.href, '_blank'); }, // 修改密码 updatePasswordHandle () { this.updatePassowrdVisible = true this.$nextTick(() => { this.$refs.updatePassowrd.init() }) }, // 退出 logoutHandle () { this.$confirm(`确定进行[退出]操作?`, '提示', { confirmButtonText: '确定', cancelButtonText: '取消', type: 'warning' }).then(() => { this.$http({ url: this.$http.adornUrl('/sys/logout'), method: 'post', data: this.$http.adornData() }).then(({data}) => { if (data && data.code === 0) { clearLoginInfo() this.$router.push({ name: 'login' }) } }) }).catch(() => {}) }, openSideMenusHandle (parentMenuIds) { // alert(parentMenuIds) this.mainTabs = [] //清除打开的tab菜单 this.menuActiveName = '' // 左侧菜单显示 this.$store.state.common.sidebarIsShow = true // 折叠打开 this.$store.state.common.sidebarFold = false // 这里调用左侧菜单的方法 EventBus.$emit('callMethod',parentMenuIds); // 再次调用,防止点击监控中心--然后跳转到其他菜单时无反应 setTimeout(() => { // alert('延时加载') EventBus.$emit('callMethod',parentMenuIds); }, 150); setTimeout(() => { // alert('延时加载') EventBus.$emit('callMethod',parentMenuIds); }, 100); setTimeout(() => { // alert('延时加载') EventBus.$emit('callMethod',parentMenuIds); }, 220); setTimeout(() => { // alert('延时加载') EventBus.$emit('callMethod',parentMenuIds); }, 120); // this.$router.push({ name: 'center' }) // center home }, openHomeHandle () { // alert("jianko") // this.mainTabs = [] //清除打开的tab菜单 // this.menuActiveName = '' // this.isHomePage = true // 折叠关闭 this.$store.state.common.sidebarFold = true // 左侧菜单显示关闭 this.$store.state.common.sidebarIsShow = false this.$router.push({ name: 'home' }) }, //--------------------------------------------------------------------------------------------------- // tabs, 关闭全部tab tabsCloseAllHandle () { this.mainTabs = [] this.menuActiveName = '' this.$router.push({ name: 'home' }) }, reloadMenus(parentMenuIds){ this.$http({ url: this.$http.adornUrl('/sys/menu/navappoint'), method: 'get', // params: this.$http.adornParams() params: this.$http.adornParams({ 'parentMenuIds': parentMenuIds }) }).then(({data}) => { if (data && data.code === 0) { // alert("获取导航菜单成功") this.fnAddDynamicMenuRoutes(data.menuList) this.$router.options.isAddDynamicMenuRoutes = true sessionStorage.setItem('menuList', JSON.stringify(data.menuList || '[]')) sessionStorage.setItem('permissions', JSON.stringify(data.permissions || '[]')) // sessionStorage.setItem('menuList', '[]') // sessionStorage.setItem('permissions', '[]') // alert("添加菜单") // 这里调用左侧菜单的方法 EventBus.$emit('callMethod',parentMenuIds); this.tabsCloseAllHandle (); // 折叠打开 this.$store.state.common.sidebarFold = false this.$router.push({ name: 'home' }) // next({ ...to, replace: true }) // 刷新 // location.reload() // alert("前往首页") } else { sessionStorage.setItem('menuList', '[]') sessionStorage.setItem('permissions', '[]') // 折叠缩进 this.$store.state.common.sidebarFold = true next() } }).catch((e) => { // alert("请求菜单列表和权限失败-to.path="+to.path) console.log(`%c${e} 请求菜单列表和权限失败,跳转至登录页!!`, 'color:blue') // alert("权限失败login") // this.$router.push({ name: 'login' }) }) }, /** * 添加动态(菜单)路由 * @param {*} menuList 菜单列表 * @param {*} routes 递归创建的动态(菜单)路由 */ fnAddDynamicMenuRoutes (menuList = [], routes = []) { var temp = [] for (var i = 0; i < menuList.length; i++) { if (menuList[i].list && menuList[i].list.length >= 1) { temp = temp.concat(menuList[i].list) } else if (menuList[i].url && /\S/.test(menuList[i].url)) { menuList[i].url = menuList[i].url.replace(/^\//, '') var route = { path: menuList[i].url.replace('/', '-'), component: null, name: menuList[i].url.replace('/', '-'), meta: { menuId: menuList[i].menuId, title: menuList[i].name, isDynamic: true, isTab: true, iframeUrl: '' } } // url以http[s]://开头, 通过iframe展示 if (isURL(menuList[i].url)) { route['path'] = `i-${menuList[i].menuId}` route['name'] = `i-${menuList[i].menuId}` route['meta']['iframeUrl'] = menuList[i].url } else { try { route['component'] = _import(`modules/${menuList[i].url}`) || null } catch (e) {} } routes.push(route) } } if (temp.length >= 1) { this.fnAddDynamicMenuRoutes(temp, routes) } else { var mainRoutes = { name: 'main-dynamic', children: routes, path: '/' } // mainRoutes.name = 'main-dynamic' // mainRoutes.children = routes this.$router.addRoutes([ mainRoutes, { path: '*', redirect: { name: '404' } } ]) sessionStorage.setItem('dynamicMenuRoutes', JSON.stringify(mainRoutes.children || '[]')) console.log('\n') console.log('%c!<-------------------- 动态(菜单)路由 s -------------------->', 'color:blue') console.log(mainRoutes.children) console.log('%c!<-------------------- 动态(菜单)路由 e -------------------->', 'color:blue') } }, /** * 添加动态(菜单)路由 * @param {*} menuList 菜单列表 * @param {*} routes 递归创建的动态(菜单)路由 */ fnAddDynamicMenuRoutes2 (menuList) { var routes = [] var temp = [] // alert("添加动态(菜单)路由--"+menuList.length) for (var i = 0; i < menuList.length; i++) { // alert("添加动态URL----"+menuList[i].url) if (menuList[i].list && menuList[i].list.length >= 1) { temp = temp.concat(menuList[i].list) } else if (menuList[i].url && /\S/.test(menuList[i].url)) { menuList[i].url = menuList[i].url.replace(/^\//, '') var route = { path: menuList[i].url.replace('/', '-'), component: null, name: menuList[i].url.replace('/', '-'), meta: { menuId: menuList[i].menuId, title: menuList[i].name, isDynamic: true, isTab: true, iframeUrl: '' } } // alert("添加动态=isTab==="+route['meta']['isTab']) // url以http[s]://开头, 通过iframe展示 if (isURL(menuList[i].url)) { route['path'] = `i-${menuList[i].menuId}` route['name'] = `i-${menuList[i].menuId}` route['meta']['iframeUrl'] = menuList[i].url // alert("添加动态=isTab==="+route['meta']['isTab']) } else { try { route['component'] = _import(`modules/${menuList[i].url}`) || null } catch (e) {} } routes.push(route) } } if (temp.length >= 1) { this.fnAddDynamicMenuRoutes(temp, routes) } else { var mainRoutes = { name: 'main-dynamic', children: routes, path: '/' } // mainRoutes.name = 'main-dynamic' // mainRoutes.children = routes this.$router.addRoutes([ mainRoutes, { path: '*', redirect: { name: '404' } } ]) sessionStorage.setItem('dynamicMenuRoutes', JSON.stringify(mainRoutes.children || '[]')) console.log('\n') console.log('%c!<-------------------- 动态(菜单)路由 s -------------------->', 'color:blue') console.log(mainRoutes.children) console.log('%c!<-------------------- 动态(菜单)路由 e -------------------->', 'color:blue') } } //---------------------------------------------------------------------------------------------------------------------- } } </script> <style> #myNavbar .el-menu-item:hover { background-color: transparent !important; color: inherit !important; } /* 顶部菜单点击后的背景颜色 */ #myNavbar .el-menu-item.is-active { background-color:rgb(15, 89, 164) !important; color:rgb(235, 184, 17); /*选中颜色*/ span { color: #fff !important; } } /* 驾驶舱鼠标悬浮时 样式文件或组件内样式 */ #myNavbar .el-submenu__title:hover { background-color:rgb(15, 89, 164) !important; /* 使用!important确保覆盖默认样式 */ } .site-navbar__menu .el-menu-item, .site-navbar__menu .el-submenu > .el-submenu__title { height: 38px; line-height: 38px; } /* 左侧菜单选中与悬停样式 */ #myzhedie:hover { background-color: #409EFF !important; /* 使用!important确保覆盖默认样式 */ color: inherit !important; } #myzhedie.is-active { background-color: rgba(126, 203, 252, 1) !important; /* 使用!important确保覆盖默认样式 */ } #myhome1:hover { background-color: rgba(126, 203, 252, 1) !important; /* 使用!important确保覆盖默认样式 */ color: inherit !important; } #myhome1.is-active { background-color: rgba(126, 203, 252, 1) !important; /* 使用!important确保覆盖默认样式 */ } #myshezhi:hover { background-color: #409EFF !important; /* 使用!important确保覆盖默认样式 */ color: inherit !important; } #myshezhi.is-active { background-color: rgba(126, 203, 252, 1) !important; /* 使用!important确保覆盖默认样式 */ } #mydaping:hover { background-color: #409EFF !important; /* 使用!important确保覆盖默认样式 */ color: inherit !important; } #mydaping.is-active { background-color: rgba(126, 203, 252, 1) !important; /* 使用!important确保覆盖默认样式 */ } #myhuichu:hover { background-color: #409EFF !important; /* 使用!important确保覆盖默认样式 */ color: inherit !important; } #myhuichu.is-active { background-color: rgba(126, 203, 252, 1) !important; /* 使用!important确保覆盖默认样式 */ } /* 加载表头颜色设置 */ /* rgba(126, 203, 252, 1) rgba(211, 236, 255, 255) #cdccd9 #87CEEB; rgba(211, 236, 255, 255); rgba(137, 207, 240); */ /* .el-table thead th { color: #909399; background-color: rgba(211, 236, 255, 255); font-weight: 800; color: #1D3124; } */ </style>修改驾驶舱下拉框的背景颜色和当前菜单颜色风格一致

filetype

# 问题--设置代码补全 * `Continue - open-source AI code assistant`插件怎么添加代码补全功能呢? * 使用的是购买的deepseek api。 * 面板上有这些选项,第一个`settings`: ```text Settings Indexing③ Help4 Shortcuts User settings Show Session Tabs Wrap Codeblocks Show Chat Scrollbar Text-to-Speech Output Enable Session Titles Format Markdown Allow Anonymous Telemetry Enable Indexing Font Size14 Multiline AutocompletionsAuto Autocomplete Timeout (ms)150 Autocomplete Debounce (ms)250 Disable autocomplete in files Comma-separated list of path matchers Experimental Settings Auto-Accept Agent Edits Add Current File by Default Enable experimental tools @Codebase: use tool calling only ``` * `indexing`: ```text @codebase index Local embeddings of your codebase Indexing complete Click to re-index ``` * `help`: ```text Help center Continue Hub Visit hub.continue.dev to explore custom assistants and blocks Documentation Learn how to configure and use Continue Have an issue? Let us know on GitHub and we'll do our5 best to resolve it Join the community! Join us on Discord to stay up-to-date on the latest developments Token usage Daily token usage across models国 Quickstart Reopen the quickstart and tutorial file ``` * `shortcuts`: ```text Keyboard shortcuts Toggle Selected Model:Ctrl+ Edit highlighted code:Ctrl + I New Chat / New Chat With Selected Code / Close Continue Sidebar IfCtrl+L Chat Already In Focus: Cancel response:Ctrl + Backspace β Toggle inline edit focus:Ctrl+Shiftt+I Focus Current Chat / Add Selected Code To Current Chat / Close ContinueCtrl + Shift +L Sidebar If Chat Already In Focus: Debug Terminal:Ctrl+ Shift + R Reject Diff:Ctrl+Shift+Backspace β Accept Diff:Ctrl + Shift+Enter Reject Top Change in Diff:Alt + Ctrl + N Accept Top Change in Diff:Alt + Ctrl +Y Toggle Autocomplete Enabled:Ctrl + K + Ctrl + A Force an Autocomplete Trigger:Ctrlj+ Alt + Space Toggle Full Screen:Ctrl + K + Ctrl + M ``` # 问题 * `ctrl + shift + p`后,搜索`Continue: Edit Config File`,发现没有对应内容: ```text Continue Console:焦点在 Continue Console 视图上 Continue Console: Focus on Continue Console View Continue:焦点在 Continue 视图上 Continue: Focus on Continue View Continue: Continue: Force Next Edit 聊天:打开聊天(Edit) Chat: Open Chat (Edit) ``` * 在扩展里面找到`continue`插件,点击设置,有这些按钮: ```text Continue: Disable Quick Fix Disable the quick fix feature. Continue: Enable Console Enable a console to log and explore model inputs and outputs.It can be found in the bottom panel. Continue: Enable Quick Actions Enable the experimental Quick Actions feature. Read our walkthrough to learn about configuration and how to share feedback: continue.dev > Walkthrough: Quick Actions (experimental) Continue: Enable Tab Autocomplete \ Enable Continue's tab autocomplete feature. Read our walkthrough to learn about configuration and how to share feedback: continue.dev > Walkthrough: Tab Autocomplete (beta) Continue: Pause Codebase Index On Start Pause Continue's codebase index on start. Continue: Pause Tab Autocomplete On Battery Pause Continue's tab autocomplete feature when your battery is low. Continue: Remote Config Server Url If your team is set up to use shared configuration, enter the server URL here and your user token below to enable automatic syncing. Continue: Remote Config Sync Period The period of time in minutes between automatic syncs. 60 Continue: Show Inline Tip Show inline suggestion to use the Continue keyboard shortcuts (e.g."Cmd/Ctrl L to select code, Cmd/trl I to edit"). Continue: Telemetry Enabled Continue collects anonymous usage data, cleaned of Pll to help us improve the product for our users. Read more at continue.dev> Telemetry. Continue: User Token If your team is set up to use shared configuration, enter your user token here and your server URL above to enable automatic syncing. ```

filetype

import streamlit as st import pandas as pd import plotly.express as px from datetime import datetime # 设置页面配置 st.set_page_config( page_title="零花钱分析师", page_icon=" ", layout="wide" ) # 设置页面标题 st.title(" 零花钱分析师") st.markdown("### 记录你的零花钱使用情况") # 初始化会话状态 if 'transactions' not in st.session_state: st.session_state.transactions = [] # 侧边栏- 添加新交易 with st.sidebar: st.header("添加新交易") date = st.date_input("日期", datetime.now()) amount = st.number_input("金额", min_value=0.0, step=0.01) category = st.selectbox("类别",["零食", "文具", "玩具", "游戏", "其他"]) description = st.text_input("描述") if st.button("添加交易"): new_transaction = { "日期": date, "金额": amount, "类别": category, "描述": description } st.session_state.transactions.append(new_transaction) # 主界面 if st.session_state.transactions: # 转换为DataFrame # df = pd.DataFrame() df = pd.DataFrame(st.session_state.transactions) # 显示交易记录 st.subheader("交易记录") st.dataframe(df) # 可视化 st.subheader("支出分析图表") # 按类别统计 fig_category = px.pie(df, values='金额', names='类别', title='支出类别分布' ) st.plotly_chart(fig_category) else: st.info("还没有添加任何交易记录,请在左侧添加你的第一笔交易!") # 添加页脚 st.markdown("---") st.markdown("###使用提示") st.markdown(""" 1. 在左侧添加你的每一笔支出 2. 查看图表了解你的支出类别分布 """)解释代码

crazed1987
  • 粉丝: 42
上传资源 快速赚钱