我正在尝试将Nivo Slider集成到应用程序http://www.jqueryscript.net/slider/nivo-slider.html中,但没有任何成功。
以下是index.html中的代码
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
<title></title>
<link href="lib/ionic/css/ionic.css" rel="stylesheet">
<link href="css/style.css" rel="stylesheet">
<!-- IF using Sass (run gulp sass first), then uncomment below and remove the CSS includes above
<link href="css/ionic.app.css" rel="stylesheet">
-->
<!-- ionic/angularjs js -->
<script src="lib/ionic/js/ionic.bundle.js"></script>
<!-- cordova script (this will be a 404 during development) -->
<script src="cordova.js"></script>
<!-- your app's js -->
<script src="js/app.js"></script>
<script src="js/controllers.js"></script>
<link rel="stylesheet" href="css/default/default.css" type="text/css" media="screen" />
<link rel="stylesheet" href="css/nivo-slider.css" type="text/css" media="screen" />
</head>
<body ng-app="appName">
<ion-nav-view></ion-nav-view>
<script src="lib/jquery-1.11.2.min.js"></script>
<script type="text/javascript" src="lib/jquery.nivo.slider.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('#slider').nivoSlider();
});
</script>
</body>
</html>
以下是home.html中位于模板目录中的代码:
<ion-view view-title="Home">
<ion-content>
<h1>Home</h1>
<div class="slider-wrapper theme-default">
<div id="slider" class="nivoSlider">
<img src="img/slider/up.jpg" data-thumb="demo/images/up.jpg" alt="" title="This is an example of a caption" />
<img src="img/slider/walle.jpg" data-thumb="demo/images/walle.jpg" alt="" data-transition="slideInLeft" />
<img src="img/slider/nemo.jpg" data-thumb="demo/images/nemo.jpg" alt="" title="#htmlcaption" />
</div>
</div>
</ion-content>
</ion-view>
所有路径都是正确的,当以html格式运行时,滑块可以正常工作,但它在应用程序中不起作用。
任何帮助都将受到高度赞赏。
谢谢, Utpal。
修改
我通过controller.js尝试了ng-repeat;这触发了滑块,但我不确定如何使用它来调用图像。
Controller.js代码:
.controller('HomeCtrl', function($scope) {
$scope.slides = [
{ img: '<img src="img/slider/1.jpg" />', id: 1 }
];
})
Home.html代码:
<ion-view view-title="Home">
<ion-content>
<div class="slider-wrapper theme-default">
<div id="slider" class="nivoSlider" ng-repeat="slide in slides">
{{slide.img}}
</div>
</div>
<button class="button button-full button-assertive">
<span>SOME TAGLINE</span><i class="ion-chevron-right right"></i>
</button>
<h4 class="title">Special Offers</h4>
<hr class="rule" />
</ion-content>
</ion-view>
PS:我知道截图中的名称不同
答案 0 :(得分:0)
使用角度指令触发滑块:
<ion-view view-title="Home">
<ion-content>
<h1>Home</h1>
<div class="slider-wrapper theme-default">
<div id="slider" class="nivoSlider" my-nivo-slider>
<img src="img/slider/up.jpg" data-thumb="demo/images/up.jpg" alt="" title="This is an example of a caption" />
<img src="img/slider/walle.jpg" data-thumb="demo/images/walle.jpg" alt="" data-transition="slideInLeft" />
<img src="img/slider/nemo.jpg" data-thumb="demo/images/nemo.jpg" alt="" title="#htmlcaption" />
</div>
</div>
</ion-content>
</ion-view>
和你的指令:
angular.module('app').directive('myNivoSlider', function() {
return {
restrict: 'A',
link : function(scope, element) {
element.nivoSlider();
}
};
});
另一种方法是使用离子平台就绪功能。
angular.module('app').run(function($ionicPlatform) {
$ionicPlatform.ready(function() {
$('#slider').nivoSlider();
});
};
我更喜欢该指令,因为它是角度应用程序中用指令控制jquery插件的最佳实践。
侨 拉尔夫