响应式照片墙html,使用React.js实现的响应式照片墙页面模板

JavaScript

语言:

JaveScriptBabelCoffeeScript

确定

"use strict";

function _classCallCheck(instance, Constructor) {

if (!(instance instanceof Constructor)) {

throw new TypeError("Cannot call a class as a function");

}

}

function _possibleConstructorReturn(self, call) {

if (!self) {

throw new ReferenceError("this hasn't been initialised - super() hasn't been called");

}

return call && (typeof call === "object" || typeof call === "function") ? call : self;

}

function _inherits(subClass, superClass) {

if (typeof superClass !== "function" && superClass !== null) {

throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);

}

subClass.prototype = Object.create(superClass && superClass.prototype, {

constructor: {

value: subClass,

enumerable: false,

writable: true,

configurable: true

}

});

if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass;

}

var Layout = window.ReactSimpleMasonry;

var Block = function Block(_ref) {

var width = _ref.width;

var height = _ref.height;

var x = _ref.x;

var y = _ref.y;

var children = _ref.children;

return React.createElement(

"div", {

className: "Block",

style: {

width: width,

height: height,

transform: "translateX(" + x + "px) translateY(" + y + "px)"

}

},

children

);

};

var getColumns = function getColumns(width) {

if (width > 900) return 5;

if (width > 400) return 3;

return 2;

};

var sizes = [{

"width": 651,

"height": 803

}, {

"width": 695,

"height": 899

}, {

"width": 669,

"height": 816

}, {

"width": 685,

"height": 868

}, {

"width": 602,

"height": 852

}, {

"width": 694,

"height": 833

}, {

"width": 622,

"height": 873

}, {

"width": 650,

"height": 833

}, {

"width": 695,

"height": 879

}, {

"width": 684,

"height": 827

}, {

"width": 610,

"height": 893

}, {

"width": 693,

"height": 895

}, {

"width": 694,

"height": 876

}, {

"width": 652,

"height": 891

}, {

"width": 625,

"height": 858

}, {

"width": 643,

"height": 828

}, {

"width": 654,

"height": 878

}, {

"width": 613,

"height": 809

}, {

"width": 671,

"height": 841

}, {

"width": 650,

"height": 850

}, {

"width": 604,

"height": 894

}, {

"width": 608,

"height": 826

}, {

"width": 641,

"height": 878

}, {

"width": 631,

"height": 814

}, {

"width": 664,

"height": 809

}, {

"width": 672,

"height": 893

}, {

"width": 669,

"height": 805

}, {

"width": 628,

"height": 850

}, {

"width": 674,

"height": 886

}, {

"width": 609,

"height": 843

}, {

"width": 640,

"height": 821

}, {

"width": 675,

"height": 840

}, {

"width": 602,

"height": 847

}, {

"width": 683,

"height": 855

}, {

"width": 656,

"height": 808

}, {

"width": 645,

"height": 881

}, {

"width": 671,

"height": 826

}, {

"width": 641,

"height": 883

}, {

"width": 665,

"height": 833

}, {

"width": 682,

"height": 853

}, {

"width": 680,

"height": 839

}, {

"width": 600,

"height": 872

}, {

"width": 620,

"height": 887

}, {

"width": 605,

"height": 807

}, {

"width": 639,

"height": 874

}, {

"width": 619,

"height": 853

}, {

"width": 675,

"height": 862

}, {

"width": 700,

"height": 881

}, {

"width": 613,

"height": 863

}, {

"width": 688,

"height": 878

}, {

"width": 698,

"height": 851

}];

var Demo = function(_React$Component) {

_inherits(Demo, _React$Component);

function Demo() {

_classCallCheck(this, Demo);

return _possibleConstructorReturn(this, _React$Component.apply(this, arguments));

}

Demo.prototype.componentWillMount = function componentWillMount() {

this.setState({

width: document.body.getBoundingClientRect().width

});

};

Demo.prototype.componentDidMount = function componentDidMount() {

var _this2 = this;

window.addEventListener('resize', function() {

_this2.setState({

width: document.body.getBoundingClientRect().width

});

});

};

Demo.prototype.render = function render() {

return React.createElement(

Layout, {

className: "Layout",

width: this.state.width,

columns: getColumns(this.state.width),

gutterX: 20,

gutterY: 20,

maxHeight: 550,

collapsing: true

},

sizes.map(function(size) {

return React.createElement(

Block, {

"original-width": size.width,

"original-height": size.height

},

React.createElement("img", {

src: "http://placehold.it/" + size.width + "x" + size.height

})

);

})

);

};

return Demo;

}(React.Component);

React.render(React.createElement(Demo, null), document.querySelector('#root'));

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值