(function (win, doc) { $(doc).ready(function () { if ($('.app-head .app-navbar__search')) { $('.app-head .app-navbar__search').on('click', function (){ if ($('#search').hasClass('show')) { $('#search').removeClass('show') } else { $('#search').addClass('show').on('click', function (){ $(this).removeClass('show') }).find('.search-form').on('click', function (e) { e.stopPropagation() }) } }) } if ($('.app-head .app-navbar__toggle')) { $('.app-head .app-navbar__toggle').on('click', function(){ if ($(doc).width() >= 1200) return $('body').css({ overflow: 'hidden' }) $('.app-head .app-navbar__main .navbar__link').on('click', function (e) { e.stopPropagation() }) $('.app-head .app-navbar__main').addClass('show').one('click', function() { $(this).removeClass('show') $('body').css({ overflow: 'auto' }) }) }) } if ($('.app-page .page-article, .app-detail .app-detail__article, .culture .culture-content')) { // 分享 if ($('#share')) { $('#share').share() } // 图片处理 _article('.app-page .page-article') _article('.app-detail .app-detail__article') _article('.culture .culture-content') } function _article(el) { // 图片尺寸处理 var _width = 0, _height = 0, _ps = $(el + ' p') _ps.each(function (index, p) { if ($(p).find('img').length > 1) { var _imgs = $(p).find('img') _imgs.each(function (index, img) { if ($(img).attr('width')) { _width = Math.max(_width, +$(img).attr('width')) } else { _width = Math.max(_width, $(img).width()) } if ($(img).attr('height')) { _height = Math.max(_height, +$(img).attr('height')) } else { _height = Math.max(_height, $(img).height()) } if (_width > 0) { $(img).width(_width) } if (_height > 0) { $(img).height(_height) } var _parentWidth = $(img).parent().css('font-size', '14px').width() if (_parentWidth <= _imgs.length * _width) { $(img).width((_parentWidth - $(img).parent().text().length * 14) / _imgs.length) } }) } }) // 0-6的选择,指定弹出图片动画类型,默认随机(请注意,3.0之前的版本用shift参数) layer.photos({photos: el, anim: 5}) } }) })(window, document)