zoukankan      html  css  js  c++  java
  • full-background.js

    $(window).on('load', function () {
        $(window).trigger('resize');
    });
    
    $(function () {
      var $window = $(window),
      isLoaded = false;
    
      function resizeBg() {
        var winWidth = $window.width(),
          winHeight = $window.height(),
          viewportAspectRatio = winWidth / winHeight;
    
        $('.full-bg').each(function (index, item) {
          var $bg = $(item),
          bgWidth = $bg.width(),
          bgHeight = $bg.height(),
          aspectRatio = bgWidth / bgHeight;
    
            if (viewportAspectRatio < aspectRatio ) {
              $bg.removeClass('full-width')
                .addClass('full-height')
                .css({
                   top: 0,
                   left: -(winHeight * aspectRatio - winWidth) / 2
                 });
            } else {
              $bg.removeClass('full-height')
                .addClass('full-width')
                .css({
                  top: -(winWidth / aspectRatio - winHeight) / 2,
                  left: 0
                });
            }
        });
      }
      $window.on('resize', resizeBg);
    
      $('.full-bg').on('load', function () {
        $(window).trigger('resize');
      });
    });
    
    enquire.register('screen and (max- 760px)', {
      match: function () {
        $('.responsive-img').each(function () {
          var $img = $(this),
            src = $img.data('mobile-src');
          if (src) {
            $img.attr('src', src).show();
          } else {
            $img.hide();
          }
        });
      },
      unmatch: function () {
        $('.responsive-img').each(function () {
          var $img = $(this),
            src = $img.data('src');
          if (src) {
            $img.attr('src', src).show();
          } else {
            $img.hide();
          }
        });
      }
    });
    
    enquire.register('screen and (min- 761px)', {
      match: function () {
        $('.responsive-img').each(function () {
          var $img = $(this),
            src = $img.data('src');
          if (src) {
            $img.attr('src', src).show();
          } else {
            $img.hide();
          }
        });
      },
      unmatch: function () {
        $('.responsive-img').each(function () {
          var $img = $(this),
            src = $img.data('mobile-src');
          if (src) {
            $img.attr('src', src).show();
          } else {
            $img.hide();
          }
        });
      }
    });
  • 相关阅读:
    最新 Cocos2d-x 3.2 开发环境搭建(windows环境下)
    Apache OFbiz entity engine源代码解读
    Android 标签控件
    标准红外遥控的接收程序-松瀚汇编源程序
    uva 10548
    char* 和char[]的差别
    依据波形的转折点文件,转换成波形文件
    spring 中StoredProcedure的使用方法
    JMS的样例
    JavaScript高级编程
  • 原文地址:https://www.cnblogs.com/Brittany-yan/p/5279242.html
Copyright © 2011-2022 走看看