我正在尝试将 angular-scroll ( https://github.com/oblador/angular-scroll ) 与应用程序的基础一起使用,但它不会滚动:(
一切都在加载(所有脚本),当我在导航上滚动滚动时什么都没有发生。当我从 ui-view 中取出所有代码并将其作为一个单独的页面时它可以工作,所以我认为它与路由有关?
我使用的所有代码都来自 angular-scroll @ https://github.com/oblador/angular-scroll上的示例
这里是在线的 - http://www.medmedia.ie/ngTest/scroll
任何帮助都会很棒
干杯皮尔斯
这是 js 和模板页面:
(function() {
'use strict';
var myApp = angular.module('application', [
'ui.router',
'ngAnimate',
'duScroll',
//foundation
'foundation',
'foundation.dynamicRouting',
'foundation.dynamicRouting.animations'
]);
myApp.config(config)
myApp.run(run)
config.$inject = ['$urlRouterProvider', '$locationProvider'];
function config($urlProvider, $locationProvider) {
$urlProvider.otherwise('/scroll.html');
$locationProvider.html5Mode({
enabled: true,
requireBase: false
});
$locationProvider.hashPrefix('!');
}
function run() {
FastClick.attach(document.body);
}
myApp.controller('MyCtrl', function($scope, $document){
$scope.toTheTop = function() {
$document.scrollTopAnimated(0, 5000).then(function() {
console && console.log('You just scrolled to the top!');
});
}
var section3 = angular.element(document.getElementById('section-3'));
$scope.toSection3 = function() {
$document.scrollToElementAnimated(section3);
}
}
).value('duScrollOffset', 30);
})();
---
name: scroll
url: /scroll
animationIn: slideInRight
---
<div class="wrap" ng-controller="MyCtrl">
<nav>
<ul>
<li><a href="#section-1" du-smooth-scroll du-scrollspy>Section 1</a></li>
<li><a href="#section-2" du-smooth-scroll du-scrollspy>Section 2</a></li>
<li><a href="#section-3" du-smooth-scroll du-scrollspy>Section 3</a></li>
</ul>
</nav>
<h1>Angular.js Scrollspy Example</h1>
<section id="section-1">
<h2>Section 1</h2>
<p>Bacon ipsum dolor sit amet sausage tail capicola ground round hamburger ham hock. Short ribs pig andouille meatball, pastrami tri-tip fatback ham hock shank kielbasa swine. Rump pancetta jerky kielbasa doner beef ribs tongue hamburger strip steak drumstick andouille shoulder shank flank. Swine drumstick meatball pig beef sausage strip steak.</p>
<img src="http://lorempixel.com/1000/500/" alt="" />
</section>
<section id="section-2">
<h2>Section 2</h2>
<p>Bacon strip steak ground round, tongue pastrami short ribs pork chop venison turducken sausage sirloin. Flank chicken pork chop capicola turkey turducken cow pork loin biltong meatball drumstick pancetta filet mignon ground round fatback. Ham hock jerky short ribs brisket. Meatloaf shoulder pork chop capicola, sirloin swine pig pork. Jerky ribeye hamburger pork loin sirloin kevin bresaola boudin chuck flank. Ham hock pork belly chicken jerky rump bresaola.</p>
</section>
<section id="section-3">
<h2>Section 3</h2>
<p>Shank fatback pastrami short loin, turkey jowl kielbasa ribeye chicken jerky drumstick flank ham. Swine shankle pork belly kielbasa shoulder flank jowl, sirloin doner. Kevin tri-tip bresaola leberkas. Swine ball tip cow strip steak. Ham filet mignon pork chop, pork fatback andouille pork loin shoulder jowl swine strip steak turducken prosciutto rump.</p>
<img src="http://lorempixel.com/1000/400/" alt="" />
<p>Tongue tri-tip pastrami, shoulder rump pork belly ground round. Ham hock chuck leberkas doner, strip steak corned beef tri-tip capicola. Rump turkey ham sausage shankle. Flank shankle pork chop ham hock. Shankle venison kielbasa, pancetta swine beef ball tip t-bone bacon hamburger ground round ribeye flank. Turducken bacon bresaola, chicken kevin boudin ball tip strip steak filet mignon pork turkey shank ground round. Kielbasa fatback prosciutto pork chop, jerky ground round leberkas boudin ball tip beef shankle shoulder swine brisket.</p>
</section>
<section id="section-4">
<h2>Section 4</h2>
<img src="http://lorempixel.com/1000/600/" alt="" />
<p>Shoulder cow tenderloin chuck, pork chop jerky doner leberkas. Chuck sausage hamburger, kevin beef pork chop pork shoulder ground round ball tip turducken flank. Bresaola tri-tip meatloaf, salami venison tail pig shank shankle jowl sausage brisket cow biltong turducken. Swine turducken hamburger ball tip short loin prosciutto kevin jowl tri-tip. Doner meatloaf pork brisket.</p>
</section>
<footer>
<button ng-click="toTheTop()">Take me back!</button> or <button ng-click="toSection3()">To section 3</button>
</footer>
</div>
索引页
<!doctype html>
<html lang="en" ng-app="application">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Foundation for Apps</title>
<link href="assets/css/app.css" rel="stylesheet" type="text/css">
<script src="assets/js/foundation.js"></script>
<script src="assets/js/templates.js"></script>
<script src="assets/js/routes.js"></script>
<script src="assets/js/app.js"></script>
<style type="text/css">
html, body {
margin: 0;
padding: 0;
background: #ebebeb;
}
body, button {
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
}
h1 {
padding-top: 50px;
}
img {
max-width: 100%;
}
nav {
position: fixed;
z-index: 1;
top: 30px;
left: 0;
right: 0;
background: #fff;
background: rgba(255, 255, 255, 0.8);
}
nav li, nav ul {
list-style: none;
margin: 0;
padding: 0;
text-align: center
}
nav li, nav a {
display: inline-block;
}
nav a {
padding: 20px;
color: #333;
text-decoration: none;
}
a:hover {
background: #fff;
}
a.active {
background: #00AC7F;
color: #fff;
}
.wrap {
position: relative;
max-width: 1000px;
margin: 0 auto;
padding: 50px 20px;
}
section {
padding: 50px 0 30px 0;
}
footer {
text-align: center;
}
button {
font-size: 18px;
border: 0;
padding: 15px 30px;
background: #00AC7F;
color: #fff;
cursor: pointer;
}
</style>
</head>
<body>
<div class="grid-frame vertical">
<div class="grid-content shrink" style="padding: 0;">
<ul class="primary condense menu-bar">
<li><a ui-sref="home"><strong>Foundation for Apps</strong></a></li>
<li><a ui-sref="scroll">Scroll</a></li>
<li><a ui-sref="group">Group</a></li>
</ul>
</div>
<div ui-view autoscroll="true" class="grid-content">
</div>
</div>
</body>
</html>