123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166 |
- <template>
- <scroll-view scroll-with-animation :class="['sunui-nav-bar sticky']"
- :scroll-x="true" :show-scrollbar="false" :scroll-into-view="'tab-'+currentIndex+autoLeft">
- <view style="height: 46px;display: flex;" class="">
- <view :class="['flex-column-center', currentIndex == index && animatie ?'sunui-nav-scale':'' ]" :id="'tab-'+index" style="width: calc(100% / 4)"
- v-for="(item, index) in items" :key="index" @click="navchang" :data-index="index">
- <view :class="['nav-public', currentIndex == index ? 'nav-active' : 'nav-item']">{{item.name}}
- </view>
- <view :class="['nav-line']" :style="{width: currentIndex == index ? 'calc(100% - 14px)' : '0px'}"></view>
- </view>
- </view>
- </scroll-view>
- </template>
- <script>
- export default {
- props: {
- items: {
- type: Array,
- default: function() {
- return []
- }
- },
- isCenter: {
- type: Boolean,
- default: true
- },
- currentIndex: {
- type: Number,
- default: 0
- },
- size: {
- type: Number,
- default: 120
- },
- fontSize: {
- type: String,
- default: '28rpx'
- },
- activeFontSize: {
- type: String,
- default: '28rpx'
- },
- activeLineBg: {
- type: String,
- default: "linear-gradient(to right, #66BFFF,#3388FF)"
- },
- color: {
- type: String,
- default: "#000"
- },
- activeColor: {
- type: String,
- default: "#333333"
- },
- activeLineHeight: {
- type: String,
- default: '6rpx'
- },
- activeLineWidth: {
- type: String,
- default: "36rpx"
- },
- activeLineRadius: {
- type: String,
- default: "0rpx"
- },
- activeDirection: {
- type: String,
- default: ""
- },
- activeFontWeight: {
- type: Number,
- default: 700
- },
- margin: {
- type: Number,
- default: 0
- },
- textAlign: {
- type: String,
- default: ''
- },
- lineHeight: {
- type: String,
- default: '50rpx'
- },
- padding: {
- type: String,
- default: '0rpx'
- },
- animatie: {
- type: Boolean,
- default: true
- },
- autoLeft: {
- type: String,
- default: ''
- }
- },
- methods: {
- navchang: function(e) {
- console.log(e.currentTarget.dataset.index)
- this.$emit('change', Number(e.currentTarget.dataset.index))
- }
- }
- }
- </script>
- <style scoped>
- .sunui-nav-bar {
- width: 100%;
- display: flex;
- white-space: nowrap;
- background-color: #fff;
- justify-content: center;
- text-align: center;
- }
- .sticky {
- position: sticky;
- width: 100%;
- left: 0;
- top: 20px;
- }
- .nav-public {
- min-width: calc(100%);
- line-height: 44px;
- height: 44px;
- /*border: 1px solid red;*/
- box-sizing: border-box;
- font-size: 15px;
- color: #B2BCCB;
- }
- .nav-line {
- /*min-width: calc(100% - 14px);*/
- height: 2px;
- background: #33CEF0;
- transition: all 0.2s linear;
- }
- .nav-active {
- /*background-color: #BF1C2D;*/
- color: #33CEF0;
- /*border-bottom: 2px solid #33CEF0;*/
- }
- .nav-item {
- background-color: #FFFFFF;
- }
- @keyframes sunui-nav-scale {
- 0% {
- transform: scale(0.8);
- }
- 100% {
- transform: scale(1);
- }
- }
- .sunui-nav-scale {
- animation: sunui-nav-scale 500ms forwards;
- }
- </style>
|