zoukankan      html  css  js  c++  java
  • angularjs轮播

    轮播,在基于别人的轮播上的angular无缝轮播

    这个项目还没有达到很酷炫的效果,要在原有的基础上加上ng-animate就会好多了,目前我对他还不是很熟悉,所以这里还有欠缺

    <!DOCTYPE html>
    <html lang="en" ng-app="lunbo">
    <head>
        <meta charset="UTF-8">
        <script src="angular.min.js" type="text/javascript"></script>
        <title></title>
        <style>
            *{
                margin:0;
                padding:0
            }
            .content{600px;overflow:hidden;height:200px;position:relative;}
            ul{
                position:absolute;
                left:0;
                top:0;
                1200px;
            }
            ul li{
                200px;
                height: 200px;
               display: inline-block;
            }
            img{
                100%;
                height:100%;
            }
    
        </style>
    </head>
    <body ng-controller="lunboController">
    <div lunbo ></div>
    <script type="text/ng-template" id="lunbo.html">
    <div class="content">
        <ul>
            <li ng-repeat="img in images"
                class="fade" >
                <a href="{{img.href}}"><img src="{{img.src}}" alt=""/></a></li>
        </ul>
    </div>
        <div class="incon1" ng-click="prev()">111</div>
        <div class="incon2" ng-click="next()">222</div>
    </script>
    </body>
    <script>
        var app=angular.module('lunbo',[]);
        app.controller('lunboController',['$scope','readJSON', function ($scope,readJSON) {
    
        }]);
        app.factory('readJSON',['$http','$q', function ($http,$q) {
            return {
                query: function () {
                    var deferred=$q.defer();
                    $http({
                        method:'GET',
                        url:'img.json'
                    }).success(function (data, status, header, config) {
                        deferred.resolve(data);
                    }).error(function (data, status, header, config) {
                        deferred.reject(data);
                    });
                    return deferred.promise;
                }
            }
        }]);
        app.directive('lunbo',['readJSON','$interval', function (readJSON,$interval) {
            return{
                restrict:'EA',
                templateUrl:'lunbo.html',
                scope:{},
                link: function (scope, element, attr) {
                    var promise=readJSON.query();
                    scope.flag=false;
                    promise.then(function (data) {
                        console.log(data);
                        scope.images=data;
                    });
                    scope.step=0;
                    var timer
                    scope.prev=function(){
                        if(scope.step==0){
                            element.find("ul").css("left","-600px");
                            scope.step=3
                        }
                        var jiuzhi=-scope.step*200;
                        --scope.step;
                        var nowzhi=-scope.step*200;
                        $interval.cancel(timer)
                        timer=$interval(function(){
                            if(jiuzhi>=nowzhi){
                                $interval.cancel(timer)
                            }else{
                                jiuzhi = jiuzhi+40
                                element.find("ul").css("left",jiuzhi+'px');
                            }
    
                        },100)
                    }
                    scope.next=function(){
                        if(scope.step==3){
                            element.find("ul").css("left","-400px");
                            scope.step=0
                        }
                        var jiuzhi=-scope.step*200;
                        ++scope.step;
                        var nowzhi=-scope.step*200;
                        $interval.cancel(timer)
                        timer=$interval(function(){
                            if(jiuzhi<=nowzhi){
                                $interval.cancel(timer)
                            }else{
                                jiuzhi = jiuzhi-40
                                element.find("ul").css("left",jiuzhi+'px');
                            }
    
                        },100)
                    }
                }
            }
        }]);
    
    </script>
    </html>
      //img.json


    {
    "href":"http://www.google.com", "src":"img/1.jpg", "alt":"1" }, { "href":"http://www.google.com", "src":"img/2.jpg", "alt":"2" }, { "href":"http://www.google.com", "src":"img/3.jpg", "alt":"1" }, { "href":"http://www.google.com", "src":"img/1.jpg", "alt":"1" }, { "href":"http://www.google.com", "src":"img/2.jpg", "alt":"2" }, { "href":"http://www.google.com", "src":"img/3.jpg", "alt":"1" } ]
  • 相关阅读:
    利用无线网络数据包分析无线网络安全
    C++ basic
    几道题目
    Pythonunittestddt(应用到类,实际参数化)
    Pythonunittestddt(基本应用)
    【第二章】处理数据源信息(config、excel数据源处理
    Python操作excel003(封装读取excel类
    Python+selenium 【第一章】什么叫ui自动化以及环境搭建
    【第五章】接口关联 正则表达式jsonpath模块
    【第四章】封装request类
  • 原文地址:https://www.cnblogs.com/heyinwangchuan/p/6736668.html
Copyright © 2011-2022 走看看