前端开发日常需求解决方法

1、图片动态展示
在这里插入图片描述
在这里插入图片描述

<template>
  <div class="container">
    <div class="url-container">
      <ul> 
        <li v-for="(item,index) in list" :key='index' @mouseenter="handleToEnter(item,index)" 
        :class="[activeIndex == index? 'active': '', {'index1': !index}]"> //给li标签的第一项添加样式。!index为true.
          <div class="item-style">
            <h4>{{item.title}}</h4>
          </div>
          <div class="div1" :style="{background: item.color}"></div>
        </li> 
      </ul>
    </div>
  </div>
</template>
<script>
export default {
  name: 'homeheader',
  data () {
    return {
      list: [{
        id: 1,
        title: '园林酒店',
        color: 'url(//file.40017.cn/js40017cnproduct/cn/h/elong_pc/common/pic/20150422_ifold1.jpg) no-repeat center 0'
      },{
        id: 2,
        title: '情侣酒店',
        color: 'url(//file.40017.cn/js40017cnproduct/cn/h/elong_pc/common/pic/20150120_ifold2.jpg) no-repeat center 0'
      },{
        id: 3,
        title: '设计师酒店',
        color: 'url(//file.40017.cn/js40017cnproduct/cn/h/elong_pc/common/pic/20150120_ifold3.jpg) no-repeat center 0'
      },{
        id: 4,
        title: '青年旅舍',
        color: 'url(//file.40017.cn/js40017cnproduct/cn/h/elong_pc/common/pic/20150120_ifold4.jpg) no-repeat center 0'
      },{
        id: 5,
        title: '特色客栈',
        color: 'url(//file.40017.cn/js40017cnproduct/cn/h/elong_pc/common/pic/20150120_ifold5.jpg) no-repeat center 0'
      },{
        id: 6,
        title: '海岛酒店',
        color: 'url(//file.40017.cn/js40017cnproduct/cn/h/elong_pc/common/pic/20150120_ifold6.jpg) no-repeat center 0'
      },{
        id: 7,
        title: '海外温泉',
        color: 'url(//file.40017.cn/js40017cnproduct/cn/h/elong_pc/common/pic/20150120_ifold7.jpg) no-repeat center 0'
      }],
      activeIndex: null,
    }
  },
  methods: {
    handleToEnter(item,index) {
      this.activeIndex = index
      let a =document.getElementsByTagName('li')
      if (index == 0) {
        a[0].style.width = '402px'
      }else{
        a[0].style.width = '133px'
      }
    }
  }
}
</script>
<style lang='scss'>
.container{
  margin-top: 100px;
  .url-container{
    width: 1200px;
    overflow: hidden;
    margin: 0 auto;
    ul{
      width: 1200px;
      height: 260px;
      margin: 0 auto;
      overflow: hidden;
      li{
        float: left;
        width: 133px;
        height: 260px;
        position: relative;
        overflow: hidden;
        cursor: pointer;
        -webkit-transition: width .5s;
        transition: width .5s;
        display: flex;
        justify-content: center;
        align-items: center;
        .item-style{
          position: absolute;
          overflow: hidden;
          width: 100%;
          height: 100%;
          left: 0;
          top: 0;
          background: rgba(0,0,0,.3);
          h4{
            color: #fff;
            width: 30px;
            margin: 0 auto;
            display: block;
            font: 30px/30px Microsoft Yahei;
            position: relative;
            padding: 60px 0 0 0;
          }
        }  
      }
      .div1{
        width: 100%;
        height: 100%;
      }
      .active{
        width: 402px;
      }
      .index1{
        width: 402px;
      }
    }
  }
}
</style>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值