'滑块角度'单击小图像会返回相应的大图像
'slider angular' Clicking on the small images return the corresponding large images
我使用了一个幻灯片放映,因为站点:http://www.sitepoint.com/creating-slide-show-plugin-angularjs/
添加了小侧面图像。我想知道当我点击小图像返回相应的大图像时该怎么办。
添加了以下代码的缩略图:(placetemplateurl.html)
<ul class="minimage" ng-show="image.visible" >
<a ng-click="returner()"> <img ng-repeat="image in images" ng-src="/sliderAngular/img/{{image.src}}" width="70" height="56"/> </a>
</ul>
这是我的尝试,它可以使它工作吗?(place app.js)
scope.currentIndex=0;
scope.returner=function(){
scope.currentIndex= ;
};
几天来,我一直试图真正需要一个知道的人的帮助,但都没有成功。如果你需要更多的信息,你可以问我,我的英语和棱角都很有限。
实际上,您最初共享的代码有很多错误,其中一些是:
- UL标签没有li项目
- ng show="image.visible"在ng repeat之外,因此图像总是未定义的
- ng重复出现在img标签上,所以只有一个链接里面有很多图片
使用$index的代码示例(属性在ng重复指令中可用):
<ul class="minimage" ng-show="images.length"> <!-- show if there are items -->
<li ng-repeat="image in images"><a ng-click="returner($index)"><img ng-src="/sliderAngular/img/{{image.src}}" width="70" height="56"/></a></li>
</ul>
和:
scope.currentIndex=-1;
scope.returner = function(index){
scope.currentIndex = index;
};
几个月前,我设法按照它想要的方式离开了它,现在我记住了这个问题,并回来为未来的读者提供了一个更完整的答案。
将此代码放在您想要显示滑块的位置下方
<div ng-app="myApp">
<div ng-controller="MyCtrl">
<div images="images" class="slider" id="mauseOnOut">
<div class="slide" ng-repeat="image in images" ng-show="image.visible">
<a ng-href="{{image.url}}"><img ng-src="{{image.src}}" width="444" height="250"/>
<p class="texto">{{image.texto}}</p>
</a>
</div>
<ul class="minimagem" ng-show="images.length">
<li ng-repeat="image in images"><a ng-click="returner($index)"><img ng-src="{{image.src}}" width="70" height="56"/></a></li>
</ul>
<div class="arrows">
<a href="" ng-click="prev()" ><img src="http://s5.postimg.org/orczpkx0z/left_arrow.png"/></a> <a href="" ng-click="next()"><img src="http://s5.postimg.org/qkfwdwi7n/right_arrow.png"/></a>
</div>
</div>
</div>
</div>
将以下代码放入您的app.js
、controller
或directives
的特定页面中。
myApp.directive('images', function factory($timeout) {
var directiveDefinitionObject = {
transclude: false,
restrict: 'AE',
multiElement: true,
scope: {
images: '='
},
link: function postLink(scope, iElement, iAttrs) {
scope.currentIndex=0;
scope.returner = function(index){
scope.currentIndex = index;
};
scope.next=function(){
scope.currentIndex<scope.images.length-1?scope.currentIndex++:scope.currentIndex=0;
};
scope.prev=function(){
scope.currentIndex>0?scope.currentIndex--:scope.currentIndex=scope.images.length-1;
};
scope.$watch('currentIndex',function(){
scope.images. forEach(function(image){
image.visible=false;
});
scope.images[scope.currentIndex].visible=true;
});
// Start: For Automatic slideshow
var timer;
var sliderFunc=function(){
timer=$timeout(function(){
scope.next();
timer=$timeout(sliderFunc,3000);
},3000);
};
sliderFunc();
scope.$on('$destroy',function(){
$timeout.cancel(timer);
});
var myDiv = document.getElementById('mauseOnOut');
myDiv.onmouseover = function() {
$timeout.cancel(timer);
};
myDiv.onmouseout = function() {
timer=$timeout(sliderFunc,3000);
};
// End : For Automatic slideshow
}
};
return directiveDefinitionObject;
});
将下面的代码放入您的controller
中,并根据您的意愿进行编辑:
$scope.images = [
{
src:'http://s5.postimg.org/b2wzny14n/img1.png',
url:'',
texto:'Trees and mountains a pleasant and peaceful environment to live .'
},
{
src:'http://s5.postimg.org/vlrvt0f1z/img2.jpg',
url:'',
texto:'Yellow and pond landscape sky that inspires a reflection on the existence'
},
{
src:'http://s5.postimg.org/wms4i4w1j/img3.jpg',
url:'',
texto:'Yellow and pond landscape sky that inspires a reflection on the existence '
},
{
src:'http://s5.postimg.org/k0hplatkn/img4.png',
url:'',
texto:'The cold and snow prevents does not prevent good news for those seeking good '
},
{
src:'http://s5.postimg.org/nitphougn/img5.png',
url:'',
texto:'Imposing Rhino with your muscles , bones and horns forming one of the strongest animals of nature '
}
];
请参阅jsFiddle 中的CSS和滑块操作
相关文章:
- Imgur API图像搜索未返回数据
- instafeed.js返回的居中图像
- 使用纯JavaScript返回并嵌入图像,如php
- html5 canvas toDataURL 返回空白图像
- 如何使用 HTML 图像请求将数据发送到服务器,或返回数据作为响应
- 从 JavaScript 中的图像中读取像素数据会返回半透明像素的意外结果
- 使用从readAsDataURL()返回的图像数据
- 有没有一种方法可以判断图像src是否在javascript内部返回null
- 提交输入类型=“;图像“;到另一个servlet时,未能返回任何参数
- jquery裁剪图像selction未返回结果
- ajax 返回带有循环的图像长度,检查最后一个循环
- dojo/使用NodeJS请求一个png图像数组缓冲区,并将图像返回给客户端
- 当用户不进行交互时,如何使图像返回到屏幕顶部
- 图像返回到原始源OnClick
- 无法通过异步ajax调用呈现base64图像返回
- 使用Ajax预览图像:返回一个损坏的图像图标
- Blob图像返回空白图像
- javascript getImageData未从png图像返回正确的像素颜色
- 如何在单击时将图像返回到网站上的另一个位置
- 图像返回值“;空”;