This commit is contained in:
IQ 2021-08-31 08:55:46 +08:00
parent 4ebef3d5f3
commit 4c56966a4e
12 changed files with 608 additions and 2 deletions

49
.editorconfig Normal file
View File

@ -0,0 +1,49 @@
# EditorConfig is awesome: http://EditorConfig.org
# Howto with your editor:
# Sublime: https://github.com/sindresorhus/editorconfig-sublime
# top-most EditorConfig file
root = true
# Unix-style newlines with a newline ending every file
[**]
end_of_line = lf
insert_final_newline = true
# Standard at: https://github.com/felixge/node-style-guide
[**.js, **.json]
trim_trailing_whitespace = true
indent_style = space
indent_size = 2
max_line_length = 80
quote_type = single
curly_bracket_next_line = false
spaces_around_operators = true
space_after_control_statements = true
space_after_anonymous_functions = false
spaces_in_brackets = false
# https://github.com/jedmao/codepainter
[node_modules/**.js]
codepaint = false
# No Standard. Please document a standard if different from .js
[**.yml, **.html, **.css]
trim_trailing_whitespace = true
indent_style = space
indent_size = 2
# No standard. Please document a standard if different from .js
[**.md]
indent_style = space
# Standard at:
[**.py]
indent_style = space
indent_size = 4
# Standard at:
[Makefile]
indent_style = tab
indent_size = 8

8
.gitignore vendored Normal file
View File

@ -0,0 +1,8 @@
.sass-cache
node_modules
dist
*.sublime-workspace
Thumbs.db

2
Gemfile Normal file
View File

@ -0,0 +1,2 @@
source 'https://rubygems.org'
gem 'compass'

31
Gemfile.lock Normal file
View File

@ -0,0 +1,31 @@
GEM
remote: https://rubygems.org/
specs:
chunky_png (1.3.4)
compass (1.0.3)
chunky_png (~> 1.2)
compass-core (~> 1.0.2)
compass-import-once (~> 1.0.5)
rb-fsevent (>= 0.9.3)
rb-inotify (>= 0.9)
sass (>= 3.3.13, < 3.5)
compass-core (1.0.3)
multi_json (~> 1.0)
sass (>= 3.3.0, < 3.5)
compass-import-once (1.0.5)
sass (>= 3.2, < 3.5)
ffi (1.9.8)
multi_json (1.11.1)
rb-fsevent (0.9.5)
rb-inotify (0.9.5)
ffi (>= 0.5.0)
sass (3.4.15)
PLATFORMS
ruby
DEPENDENCIES
compass
BUNDLED WITH
1.10.1

21
LICENSE Normal file
View File

@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) 2015 Dimitar Stojanov
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@ -1,3 +1,32 @@
# flexbox # Flexbox Playground CSS3 FlexBox 在线调试
CSS3 FlexBox 在线调试 This is project to demonstrate the capabilities of the CSS3 Flexbox Layout.
## Prerequisites
In order to build this project you need to have Node.js and npm (Node Package Manager) installed on your system. You can download them from [here](https://nodejs.org/download/) and follow this [install instructions](https://github.com/joyent/node/wiki/Installing-Node.js-via-package-manager).
To compile the Sass source to CSS, you'll need Ruby, Sass and Compass. To install Ruby follow this [guide](https://www.ruby-lang.org/en/documentation/installation/), for Sass [this](http://sass-lang.com/install), and for Compass refer to [this guide](http://compass-style.org/install/).
In some cases when installing node packages you'll need [Python 2.7](https://www.python.org/downloads/) and [C++ Libraries](https://support.microsoft.com/en-us/kb/2977003) (Windows) to build them.
Note that these executables need to be accessed from command line, so make sure they're added in the environment path. On Linux and Mac they're automatically added to the path, and for Windows you may need to follow this [instructions](http://www.computerhope.com/issues/ch000549.htm), just be careful not to mess the existing path value.
## Setup
First install gulp command line tool globally with:
`npm install --global gulp`
And from the project's root install the dependencies with:
`npm install`
After it's done, this will attempt to run `bundle` in the current dir to install the `compass` gem defines as a dependency in the `Gemfile`. Without the Ruby `compass` gem, `gulp build` will fail.
## Build
To build the code just run `gulp` from the command line. This will produce functional version in the `dist` folder.
## License
This source code is under [MIT license](https://github.com/imjustd/flexbox-playground/blob/master/LICENSE).

View File

@ -0,0 +1,11 @@
{
"folders":
[
{
"follow_symlinks": true,
"path": ".",
"folder_exclude_patterns": ["node_modules", ".sass-cache", ".git"],
"file_exclude_patterns": ["*.sublime-workspace"]
}
]
}

61
gulpfile.js Normal file
View File

@ -0,0 +1,61 @@
var gulp = require('gulp'),
gutil = require('gulp-util'),
jshint = require('gulp-jshint'),
compass = require('gulp-compass'),
concat = require('gulp-concat'),
uglify = require('gulp-uglify'),
input = {
'html': 'source/*.html',
'sass': 'source/sass/**/*.scss',
'javascript': 'source/javascript/**/*.js'
},
output = {
'html': 'dist',
'stylesheets': 'dist/css',
'javascript': 'dist/js'
};
/* run javascript through jshint */
gulp.task('jshint', function() {
return gulp.src(input.javascript)
.pipe(jshint())
.pipe(jshint.reporter('jshint-stylish'));
});
/* concat javascript files, minify if --type production */
gulp.task('build-js', function() {
return gulp.src(input.javascript)
.pipe(concat('app.js'))
//only uglify if gulp is ran with '--type production'
.pipe(gutil.env.type === 'production' ? uglify() : gutil.noop())
.pipe(gulp.dest(output.javascript));
});
/* compile scss files */
gulp.task('build-css', function() {
return gulp.src(input.sass)
.pipe(compass({
css: 'dist/css',
sass: 'source/sass'
}))
.pipe(gulp.dest(output.stylesheets));
});
/* copy any html files to dist */
gulp.task('copy-html', function() {
return gulp.src(input.html)
.pipe(gulp.dest(output.html));
});
/* Watch these files for changes and run the task on update */
gulp.task('watch', function() {
gulp.watch(input.javascript, ['jshint', 'build-js']);
gulp.watch(input.sass, ['build-css']);
gulp.watch(input.html, ['copy-html']);
});
/* run the watch task when gulp is called without arguments */
gulp.task('default', ['jshint', 'build-js', 'build-css', 'copy-html', 'watch']);

31
package.json Normal file
View File

@ -0,0 +1,31 @@
{
"name": "flexbox-playground",
"version": "1.0.0",
"description": "Web demo to demonstrate CSS3 flexbox properties",
"homepage": "http://invoicebus.com",
"repository": "imjustd/flexbox-playground",
"main": "index.js",
"keywords": [
"CSS3",
"flexbox",
"demo"
],
"author": "Dimitar Stojanov <dimitar@invoicebus.com>",
"license": "MIT",
"engines": {
"node": ">= 0.10"
},
"devDependencies": {
"gulp": "^3.8.11",
"gulp-compass": "^2.0.3",
"gulp-concat": "^2.5.2",
"gulp-jshint": "^1.9.2",
"gulp-sourcemaps": "^1.3.0",
"gulp-uglify": "^1.1.0",
"gulp-util": "^3.0.4",
"jshint-stylish": "^1.0.1"
},
"scripts": {
"postinstall": "which bundle && bundle"
}
}

205
source/index.html Normal file
View File

@ -0,0 +1,205 @@
<!DOCTYPE html>
<!-- tell angular this is flexboxDemoApp -->
<html lang="en" ng-app="flexboxDemoApp">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>CSS3 Flexbox Playground</title>
<!-- Angulars Material CSS -->
<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/angular_material/0.8.3/angular-material.min.css">
<!-- include our compiled CSS -->
<link href="css/style.css" rel="stylesheet">
</head>
<!-- this will be the only controller AppCtrl -->
<body ng-controller="AppCtrl">
<!-- Here's the main container -->
<md-content class="md-padding">
<div layout-gt-md="row" layout="column">
<div flex-gt-md="66" flex="100" class="right-padding">
<h3>Children Width</h3>
<div layout="row" layout-align="center center" class="code">
<div flex="15">width: {{children_width}}%</div>
<md-slider flex min="0" max="100" ng-model="children_width" aria-label="width"></md-slider>
</div>
<md-divider></md-divider>
<h3>Parent Flex Properties &ndash; <span class="highlight">flex container</span></h3>
<div layout="column" layout-gt-md="row" class="code">
<div layout="row">
<div flex>
<strong>flex-direction</strong>
<md-radio-group ng-model="parent.flexDirection">
<md-radio-button value="row" class="highlight">row</md-radio-button>
<md-radio-button value="row-reverse">row-reverse</md-radio-button>
<md-radio-button value="column">column</md-radio-button>
<md-radio-button value="column-reverse">column-reverse</md-radio-button>
</md-radio-group>
</div>
<div flex>
<strong>flex-wrap</strong>
<md-radio-group ng-model="parent.flexWrap">
<md-radio-button value="nowrap" class="highlight">nowrap</md-radio-button>
<md-radio-button value="wrap">wrap</md-radio-button>
<md-radio-button value="wrap-reverse">wrap-reverse</md-radio-button>
</md-radio-group>
</div>
</div>
<div layout="row">
<div flex>
<strong>justify-content</strong>
<md-radio-group ng-model="parent.justifyContent">
<md-radio-button value="flex-start" class="highlight">flex-start</md-radio-button>
<md-radio-button value="flex-end">flex-end</md-radio-button>
<md-radio-button value="center">center</md-radio-button>
<md-radio-button value="space-between">space-between</md-radio-button>
<md-radio-button value="space-around">space-around</md-radio-button>
</md-radio-group>
</div>
<div flex>
<strong>align-items</strong>
<md-radio-group ng-model="parent.alignItems">
<md-radio-button value="stretch" class="highlight">stretch</md-radio-button>
<md-radio-button value="flex-start">flex-start</md-radio-button>
<md-radio-button value="flex-end">flex-end</md-radio-button>
<md-radio-button value="center">center</md-radio-button>
<md-radio-button value="baseline">baseline</md-radio-button>
</md-radio-group>
</div>
</div>
<div layout="row">
<div flex>
<strong>align-content</strong>
<md-radio-group ng-model="parent.alignContent">
<md-radio-button value="stretch" class="highlight">stretch</md-radio-button>
<md-radio-button value="flex-start">flex-start</md-radio-button>
<md-radio-button value="flex-end">flex-end</md-radio-button>
<md-radio-button value="center">center</md-radio-button>
<md-radio-button value="space-between">space-between</md-radio-button>
<md-radio-button value="space-around">space-around</md-radio-button>
</md-radio-group>
</div>
</div>
</div>
<small>* The default property values are <span class="highlight">highlighed</span>.</small>
<md-divider></md-divider>
<h3>Children Flex Properties &ndash; <span class="highlight">flex items</span></h3>
<div>
<p>The children flex properties can be applied at child level, separate for each child. See the results section and change some of their properties. Hover with the mouse pointer or touch the fields to see the property name.</p>
</div>
<md-divider hide show-sm show-md></md-divider>
</div>
<div flex>
<h3 class="pull-left">Result</h3>
<p class="pull-right">
<md-button class="md-accent md-raised" ng-click="addChild()">Add child</md-button>
</p>
<div class="clearfix"></div>
<div
class="flexbox-parent"
ng-attr-style="
-webkit-flex-direction: {{parent.flexDirection}};
flex-direction: {{parent.flexDirection}};
-webkit-flex-wrap: {{parent.flexWrap}};
flex-wrap: {{parent.flexWrap}};
-webkit-justify-content: {{parent.justifyContent}};
justify-content: {{parent.justifyContent}};
-webkit-align-items: {{parent.alignItems}};
align-items: {{parent.alignItems}};
-webkit-align-content: {{parent.alignContent}};
align-content: {{parent.alignContent}};
"
>
<div
class="code md-whiteframe-z1"
ng-repeat="child in children"
ng-attr-style="
width: {{children_width}}%;
-webkit-order: {{child.order}};
order: {{child.order}};
-webkit-flex-grow: {{child.flexGrow}};
flex-grow: {{child.flexGrow}};
-webkit-flex-shrink: {{child.flexShrink}};
flex-shrink: {{child.flexShrink}};
-webkit-flex-basis: {{child.flexBasis}};
flex-basis: {{child.flexBasis}};
-webkit-align-self: {{child.alignSelf}};
align-self: {{child.alignSelf}};
"
>
<div class="clearfix">
<span class="child-number" aria-label="Number">{{$index + 1}}</span>
<span class="remove-child pull-right" ng-click="removeChild($index)" title="Remove">
&#x2716;
</span>
</div>
<div class="child-controls">
<md-input-container>
<md-tooltip md-direction="top">order</md-tooltip>
<input type="number" ng-model="children[$index].order">
</md-input-container>
<md-input-container>
<md-tooltip md-direction="top">flex-grow</md-tooltip>
<input type="number" ng-model="children[$index].flexGrow">
</md-input-container>
<md-input-container>
<md-tooltip md-direction="top">flex-shrink</md-tooltip>
<input type="number" ng-model="children[$index].flexShrink">
</md-input-container>
<md-input-container>
<md-tooltip md-direction="top">flex-basis</md-tooltip>
<input type="text" ng-model="children[$index].flexBasis">
</md-input-container>
<md-input-container>
<md-tooltip md-direction="top">align-self</md-tooltip>
<md-select ng-model="children[$index].alignSelf">
<md-option ng-value="value" ng-repeat="value in ['auto', 'flex-start', 'flex-end', 'center', 'baseline', 'stretch']">{{value}}</md-option>
</md-select>
</md-input-container>
</div>
</div>
</div>
</div>
</div>
</md-content>
<!-- AngularJS -->
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.6/angular-animate.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.6/angular-aria.min.js"></script>
<!-- Angular Material JavaScript -->
<script src="https://ajax.googleapis.com/ajax/libs/angular_material/0.8.3/angular-material.min.js"></script>
<!-- App.js -->
<script src="js/app.js"></script>
</body>
</html>

45
source/javascript/app.js Normal file
View File

@ -0,0 +1,45 @@
// Declare the flexboxDemoApp module and its dependency 'ngMaterial'
var app = angular.module('flexboxDemoApp', ['ngMaterial']);
// Declare the AppCtrl controller
app
.config(['$mdThemingProvider', function ($mdThemingProvider) {
$mdThemingProvider
.theme('default')
.accentPalette('amber', {
default: '700'
});
}])
.controller('AppCtrl', ['$scope', function ($scope) {
$scope.parent = {
flexDirection: 'row',
flexWrap: 'nowrap',
justifyContent: 'flex-start',
alignItems: 'stretch',
alignContent: 'stretch'
};
$scope.children_width = 12; // %
$scope.children = [];
var addChild = function (order, flexGrow, flexShrink, flexBasis, alignSelf) {
$scope.children.push({
order: order || 0,
flexGrow: flexGrow || 0,
flexShrink: flexShrink || 1,
flexBasis: flexBasis || 'auto',
alignSelf: alignSelf || 'auto'
});
};
var removeChild = function (index) {
$scope.children.splice(index, 1);
};
$scope.addChild = addChild;
$scope.removeChild = removeChild;
for (var i = 0; i < 5; i++) {
addChild();
}
}]);

113
source/sass/style.scss Normal file
View File

@ -0,0 +1,113 @@
@import "compass";
// Flex container
.flexbox-parent {
@include display-flex;
background: #FFD54F;
overflow: hidden;
width: 100%;
padding: 3px;
min-height: 550px;
max-height: 1000px;
width:50vw;
max-width:50vw;
height:50vh;
// Flex items
> div {
display: inline-block;
background: white;
overflow: hidden;
margin: 3px;
padding: 5px;
.child-controls {
margin-top: 7px;
}
}
}
.child-number {
display: block;
width: 22px;
height: 22px;
background: #FFB300;
color: white;
font-size: 14px;
font-weight: bold;
padding-top: 3px;
text-align: center;
@include border-radius(50%);
float: left;
}
.code {
font-family: Consolas, "Courier New", Monospace;
font-size: 15px;
}
.remove-child {
background: transparent;
color: #FF6F00;
font-size: 14px;
cursor: pointer;
}
.highlight {
color: #FF8F00;
}
.pull-left {
float: left;
}
.pull-right {
float: right;
}
.clearfix {
&:after {
content: '';
display: block;
clear: both;
}
}
.right-padding {
padding-right: 15px;
}
h3 {
margin: 0 0 10px 0 !important;
}
p {
margin: 0 0 10px 0 !important;
line-height: 1.4em !important;
}
md-input-container {
padding: 0 0 5px 0 !important;
.md-input {
padding: 0 !important;
line-height: 1em !important;
}
}
md-select {
margin-top: 0 !important;
.md-select-label {
padding-top: 2px !important;
padding-bottom: 4px !important;
}
}
md-radio-button {
margin: 5px 10px !important;
}
md-divider {
margin: 10px 0 !important;
}