定制 knysakpatryk/media-query-suppressor 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

knysakpatryk/media-query-suppressor

Composer 安装命令:

composer require knysakpatryk/media-query-suppressor

包简介

This library helps you to suppress media queries in your dynamic content

README 文档

README

This library helps you with "suppressing" media queries in your dynamic content. Why would you do that? You have to do that if your site is responsive (for example based on Bootstrap) and you want to create non-responsive (classic) version of your site (for mobile devices etc.).

Attention

Many people creates media queries in many ways. For example they set them up to fire and achieve classic-like appearance, so the base CSS without media queries will not be full (classic) website, but (e.g.) mobile version. Website design should be coded in another way. Base CSS without media queries should be classic, desktop version and all media queries should apply to fit other devices. Wrongly coded website enforce us to:

  1. rewrite all media queries (this can be painful)
  2. or cleverly choose suppression strategy to overcome this issue (but it's not always possible)

Installation

Edit your project's composer.json file to require knysakpatryk/media-query-suppressor

"require": {
    "knysakpatryk/media-query-suppressor": "0.1.*"
}

Usage

$suppressionStrategy = new KnysakPatryk\MediaQuerySuppressor\Strategy\ReduceStrategy();
$mediaQuerySuppressor = new KnysakPatryk\MediaQuerySuppressor\Suppressor($suppressionStrategy);

echo $mediaQuerySuppressor->one('string');
// or
print_r($mediaQuerySuppressor->many(['string 1', 'string 2']));

Suppression strategies

ReduceStrategy (recommended)

This strategy is upgraded ReplaceStrategy. It sets max-width directives to 1px (because desktop version of site should not have upper width limits) and replaces min-width directives with corresponding replacements starting from 1px. By this, you can overcome the override issue of ReplaceStrategy.

ReplaceStrategy

It sets max-width directives to 1px and min-width directives to 2px. This strategy works in the most simple cases, but can go wrong with complicated ones - because you can accidentally override other media query (which was not intended).

Example use case

Our client has website based on Bootstrap. He wants to add classic version of the site - just by clicking button in the bottom of the page. Classic version should not vary on different devices/screen sizes (non-responsive).

How can we do that?
  1. First, we create another, non-responsive CSS spreadsheet for classic version (this step can be also done by this library).
  2. Next, we use this library to "suppress" any other media queries from dynamic content (for example loaded from database).
  3. Lastly, we add button at the bottom of the page, to switch website version.

In real world scenario, it's not going to be that easy, but this is only a simple use case example.

License

The library is open-sourced software licensed under the MIT license.

统计信息

  • 总下载量: 52
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 2
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-05-07

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固