• 顶部滑动导航菜单栏


    参考:https://ext.dcloud.net.cn/plugin?id=738

    • template使用
    
    <template>
    	<view class="slidingMenu">
    		<haverster-slidingMenu :list="list" :color="color" @changes="getIndex"></haverster-slidingMenu>
    		<view class="contentList">
    			<image :src="imageList[activeIndex]" mode=""></image>
    		</view>
    	</view>
    </template>
    
    

    • JS
    <script>
    	import haversterSlidingMenu from '@/components/haverster-slidingMenu/haversterSlidingMenu.vue';
    	export default {
    		components: { haversterSlidingMenu },
    		data() {
    			return {
    				list: ['男装', '母婴', '数码', '箱包', '生鲜', '食品', '饰品', '女装'], //默认传到顶部菜单栏的数据
    				activeIndex: '0', ///菜单栏选中状态的index值
    				color: 'white', //设置菜单的背景颜色
    				imageList: [
    					'http://pic1.win4000.com/mobile/2018-09-04/5b8dece4e565c.jpg',
    					'https://ss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=239553082,2832910159&fm=115&gp=0.jpg',
    					'https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=2358570013,1985123782&fm=26&gp=0.jpg',
    					'https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=2914575322,940354749&fm=115&gp=0.jpg',
    					'https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=3065463705,1034625646&fm=115&gp=0.jpg',
    					'https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=577097343,3406258596&fm=26&gp=0.jpg',
    					"http://pic1.win4000.com/mobile/2018-09-04/5b8dece5b9dbe.jpg",
    					"http://pic1.win4000.com/mobile/2018-09-04/5b8dece9ee511.jpg"
    				],//下面图片显示
    			};
    		},
    		onLoad() {},
    		methods: {
    			getIndex(e) {
    				this.activeIndex = e;
    			}
    		}
    	};
    </script>
    
    

    • CSS
    
    page{
    		background-color: #FAFAFA;
    	}
    	.contentList {
    		 750upx;
    		height: 500px;
    		margin-top: 20upx;
    	}
    	.contentList image {
    		 100%;
    		height: 100%;
    	}
    	.slidingMenu{
    		
    	}
    
    

    • 最后附上haversterSlidingMenu.vue
    
    <template>
    	<scroll-view class="uni-slidingMenu" scroll-x :style="{background: color}">
    		<view  :class="['slidingMenuList',activeIndex==index?'active':'']" v-for="(item, index) in list" :key="index" @click="getActive(index)" v-cloak>{{ item }}</view>
    	</scroll-view>
    </template>
    
    <script>
    export default {
    	name: 'uniSlidingMenu',
    	props:{
    		// 列表菜单
    		list:{
    			type: Array,
    			// default:['首页1', '首页2', '首页3', '首页4', '首页4', '首页4', '首页4', '首页4']
    		},
    		color:{
    			type:String,
    			default:'#777777'
    		}
    		
    	},
    	data() {
    		return {
    			// list: ['首页1', '首页2', '首页3', '首页4', '首页4', '首页4', '首页4', '首页4'],
    			activeIndex:"0"
    		};
    	},
    	methods:{
    		getActive(index){
    			this.activeIndex=index;
    			this.$emit("changes",this.activeIndex);
    		}
    	}
    };
    </script>
    
    <style>
    	page{
    		background-color: #fafafa;
    	}
    /* 滑动菜单栏的总内容区域 */
    .uni-slidingMenu {
    	 100%;
    	white-space: nowrap;
    	height: 80rpx;
    	background-color: #FFFFFF;
    }
    /* 循环显示的菜单栏 */
    .slidingMenuList {
    	height: 80rpx;
    	line-height: 80rpx;
    	display: inline-block;
    	font-size: 24rpx;
    	margin-left: 60rpx;
    }
    .slidingMenuList:last-child{
    	margin-right: 60rpx;
    }
    /* 点击选中菜单栏时的样式 */
    .active {
    	color: pink;
    	font-size: 28rpx;
    	margin-left: 80rpx;
    	border-bottom: 2rpx solid pink;
    	box-sizing: border-box;
    }
    </style>
    
    
    
  • 相关阅读:
    JS实现右侧悬浮框随着页面的上下轮动而移动
    js实现一个简单的时钟表
    js实现前后端分离点击新闻列表跳转到相应的详情页
    获取当前时间的年、月、日
    点击获取今天时间、明天时间、本周时间、本月时间
    判断是不是ie7浏览器,把https换成http(兼容ie7)
    jq控制class相同点击隐藏当前相同的父元素
    js、jq控制class相同当子元素为空时,父元素隐藏
    photoshop
    不得不说一下vite
  • 原文地址:https://www.cnblogs.com/neo-java/p/11459492.html
Copyright © 2020-2023  润新知