使用isotope
和prettyPhoto
創建我的角度js
圖庫查看,但得到誤差不能呼籲在初始化之前同位素方法;試圖調用方法 '重新佈局'我在加載控制我的相冊查看如下:不能調用同位素的方法;試圖調用方法「重新佈局」 angularjs
的index.html
<ng-view></ng-view>
app.js
angular.module("myapp", ["ngRoute", "ui.bootstrap", "slickCarousel"]).
config(function($routeProvider, $locationProvider) {
$routeProvider.
when("/home", {
templateUrl: "partial views/home.html"
})
}).controller("portfolioController", function($scope, $location) {
//Portfolio
$scope.$watch("$viewContentLoaded", function() {
"use strict";
var $container = $('.portfolio'),
$items = $container.find('.portfolio-item'),
portfolioLayout = 'fitRows';
if ($container.hasClass('portfolio-centered')) {
portfolioLayout = 'masonry';
}
var init = false;
$container.isotope({
filter: '*',
animationEngine: 'best-available',
layoutMode: portfolioLayout,
animationOptions: {
duration: 750,
easing: 'linear',
queue: false
},
masonry: {}
}, refreshWaypoints());
function refreshWaypoints() {
init = true;
setTimeout(function() {}, 1000);
}
$('nav.portfolio-filter ul a').on('click', function() {
var selector = $(this).attr('data-filter');
$container.isotope({
filter: selector
}, refreshWaypoints());
$('nav.portfolio-filter ul a').removeClass('active');
$(this).addClass('active');
return false;
});
function getColumnNumber() {
var winWidth = $(window).width(),
columnNumber = 1;
if (winWidth > 1200) {
columnNumber = 5;
} else if (winWidth > 950) {
columnNumber = 4;
} else if (winWidth > 600) {
columnNumber = 3;
} else if (winWidth > 400) {
columnNumber = 2;
} else if (winWidth > 250) {
columnNumber = 1;
}
return columnNumber;
}
function setColumns() {
var winWidth = $(window).width(),
columnNumber = getColumnNumber(),
itemWidth = Math.floor(winWidth/columnNumber);
$container.find('.portfolio-item').each(function() {
$(this).css({
width: itemWidth + 'px'
});
});
}
function setPortfolio() {
setColumns();
if (init) $container.isotope('reLayout');
}
$container.imagesLoaded(function() {
setPortfolio();
});
$(window).on('resize', function() {
setPortfolio();
});
});
})
home.html的
<div id="portfoliowrap" ng-controller="portfolioController">
<h3>LATEST WORKS</h3>
<div class="portfolio-centered">
<div class="recentitems portfolio">
<div class="portfolio-item graphic-design">
<div class="he-wrap tpl6">
<img src="/img/portfolio/portfolio_09.jpg" alt="">
<div class="he-view">
<div class="bg a0" data-animate="fadeIn">
<h3 class="a1" data-animate="fadeInDown">A Graphic Design Item</h3>
<a data-rel="prettyPhoto" href="assets/img/portfolio/portfolio_09.jpg" class="dmbutton a2" data-animate="fadeInUp"><i class="fa fa-search"></i></a>
<a href="single-project.html" class="dmbutton a2" data-animate="fadeInUp"><i class="fa fa-link"></i></a>
</div><!-- he bg -->
</div><!-- he view -->
</div><!-- he wrap -->
</div><!-- end col-12 -->
<div class="portfolio-item books">
<div class="he-wrap tpl6">
<img src="/img/portfolio/portfolio_10.jpg" alt="">
<div class="he-view">
<div class="bg a0" data-animate="fadeIn">
<h3 class="a1" data-animate="fadeInDown">A Book Design Item</h3>
<a data-rel="prettyPhoto" href="assets/img/portfolio/portfolio_10.jpg" class="dmbutton a2" data-animate="fadeInUp"><i class="fa fa-search"></i></a>
<a href="single-project.html" class="dmbutton a2" data-animate="fadeInUp"><i class="fa fa-link"></i></a>
</div><!-- he bg -->
</div><!-- he view -->
</div><!-- he wrap -->
</div><!-- end col-12 -->
</div><!-- portfolio -->
</div><!-- portfolio container -->
</div><!--/Portfoliowrap -->
如您所見,我還使用$scope.$watch("$viewContentLoaded",
來確保視圖已加載。但仍然出現以上錯誤。 Isotope
工作正常,但prettyphoto
不工作,這可能是因爲這個錯誤。希望得到一些指導。
總是在指令初始化插件。 '$ viewContentLoaded'不能保證所有的渲染都完成了。在控制器中永遠不應該有任何與dom相關的代碼。我相信已經有一個角模塊包裝同位素... http://mankindsoftware.github.io/angular-isotope/ – charlietfl
@charlietfl ..我會檢查一次,讓知道.. :) –
也不'你認爲'$ viewContentLoaded'可以'$ watch',這是一個事件,你可以使用'$ on'。 Irregardless的方法是全錯了...需要指令 – charlietfl