zoukankan      html  css  js  c++  java
  • 根据屏幕大小换不同背景图片

      今天遇到了全屏翻滚的网站首页,自然客户要求图片不能大量变形,于是,我通过写两个不同的类(每个类里面的background-images属性值URL不同),在页面里面通过jq判断屏幕大小,添加和删除自定义类。

      jq代码如下:

    $(function () {
            //判断是否宽屏
            var winWide = window.screen.width;
            var wideScreen = false;
            if (winWide <= 1199) {//1199及以下分辨率
                $(".swiper-wrapper > div:nth-of-type(1)").removeClass('slide1').addClass('slide1-phone');
                $(".swiper-wrapper > div:nth-of-type(2)").removeClass('slide2').addClass('slide2-phone');
                $(".swiper-wrapper > div:nth-of-type(3)").removeClass('slide3').addClass('slide3-phone');
            } else {
                $(".swiper-wrapper > div:nth-of-type(1)").addClass('slide1').removeClass('slide1-phone');
                $(".swiper-wrapper > div:nth-of-type(2)").addClass('slide2').removeClass('slide2-phone');
                $(".swiper-wrapper > div:nth-of-type(3)").addClass('slide3').removeClass('slide3-phone');
                wideScreen = true; //是宽屏
            }
    })
    

      css代码如下:

    .slide1{
        background-image: url(../images/index-bg1.jpg);
        background-size: cover;
    }
    .slide1-phone {
        background-image: url(../images/mb-p1-bc.jpg);
        background-size: cover;
    }
    .slide2{
        background-image: url(../images/index-bg2.png);
        background-size: cover;
        text-align: center;
    }
    .slide2-phone {
        background-image: url(../images/mb-p2-bc.jpg);
        background-size: cover;
    }
    .slide3{
        background-image: url(../images/index-bg3.jpg);
        background-size: cover;
    }
    .slide3-phone {
        background-image: url(../images/mb-p3-bc.jpg);
        background-size: cover;
    }
    

      HTML代码如下:

    转载于:https://www.cnblogs.com/candy-Yao/p/7487983.html

  • 相关阅读:
    汇编结合vc6的使用
    QT textbroswer textedite Qlist的常用的操作函数
    QT Qdialog的对话框模式以及其关闭
    QT生成的exe在其他电脑打开
    c++实现服务器和多个客户端的实时群聊通信
    c++ 实时通信系统(基础知识TCP/IP篇)
    c++的并发操作(多线程)
    六种Socket I/O模型幽默讲解
    c++字符串的输入
    字符串 与其他数据类型的转换,以及字符创的常用操作
  • 原文地址:https://www.cnblogs.com/twodog/p/12139433.html
Copyright © 2011-2022 走看看