zoukankan      html  css  js  c++  java
  • AngularJS driective 封装 自动滚动插件

    1.ui-smooth-scroll.js文件内容

    angular.module('app')
        .directive('uiSmoothScroll', ['$location', '$anchorScroll', function($location, $anchorScroll) {
            return {
                restrict: 'AC',
                scope: {
                    data:"="
                },
                template: '<div class="smooth-scroll-container">'+
                        '<ul class="smooth-scroll">'+
                            '<li ng-repeat="item in data">'+
                                '<a  href="{{item.url}}" ><img ng-src="{{item.image}}" alt="" class="img-responsive" /></a>'+
                            '</li>'+
                        '</ul>'+
                    '</div>',
                link: function(scope, element, attrs) {
                    setTimeout(function(){
                        var c = $(element).find('.smooth-scroll-container')[0];
                        var ul = $(c).find('.smooth-scroll')[0];
                        var lis = ul.getElementsByTagName('li');
                        var itemCount = lis.length,
                            width = lis[0].offsetWidth,
                            marquee = function() {
                                c.scrollLeft += 2;
                                if (c.scrollLeft > width) {
                                    ul.appendChild(ul.getElementsByTagName('li')[0]);
                                    c.scrollLeft = 0;
                                };
                            },
                            speed = 30;
                        ul.style.width = (width+13) * itemCount + 40 + 'px' ;
                        var timer = setInterval(marquee, speed);
                        c.onmouseover = function() {
                            clearInterval(timer);
                        };
                        c.onmouseout = function() {
                            timer = setInterval(marquee, speed);
                        };
                    },100);
    
                }
            };
        }]);
    

      HTML 使用方法

     <div ui-smooth-scroll data="slides">
    

      Controller 中对 数据的绑定

     $scope.slides = [{ image: 'img/qy_lunbo_01.png' },{ image: 'img/qy_lunbo_02.png' },{ image: 'img/qy_lunbo_03.png' },{ image: 'img/qy_lunbo_04.png' }];
    

      

    搞定!

  • 相关阅读:
    jQuery制作焦点图(轮播图)
    mysql 存储引擎的选择
    linux 系统操作
    把网页转换成doc 格式的文件,方便用户下载PHP 方法
    多年级勾选
    zend studio 破解
    win7下安装Linux实现双系统全攻略
    【Linux】Linux中常用操作命令
    PHP xmapp 下面安装 Composer-Setup.exe
    ecshop中smarty比较操作符(eq,ne,neq)含义
  • 原文地址:https://www.cnblogs.com/pangguoming/p/7168342.html
Copyright © 2011-2022 走看看