我试图在Steroids + Angular1.3.15(AppGyver)混合应用中实现字体缩放。我决定使用$localStorage
来存储当前的字体大小。它在Android设备上运行良好,但在iOS上运行不正常。实际上在iOS中,它适用于新打开的WebViews
,但不适用于已经显示的。{/ p>
字体缩放的链接:
<a class="font-size font-small" data-remote="true" ng-class="{current: fontSize == 'rem-base-small'}" ng-click="setFontSize('rem-base-small')">A</a>
<a class="font-size font-medium" data-remote="true" ng-class="{current: fontSize == 'rem-base-medium'}" ng-click="setFontSize('rem-base-medium')">A</a>
<a class="font-size font-large" data-remote="true" ng-class="{current: fontSize == 'rem-base-large'}" ng-click="setFontSize('rem-base-large')">A</a>
并在我的控制器中:
$scope.fontSize = $localStorage.fontSize || 'rem-base-medium'
$scope.setFontSize = function(size) {
$localStorage.fontSize = size
$scope.fontSize = size
}
我在myfontsize
标记上使用<html>
指令来更新UI。我的指令如下:
var sharedStuff = angular.module('sharedStuff', ['ngStorage'])
sharedStuff.directive('myfontsize', function($localStorage) {
function link(scope, element, attrs) {
var format,
timeoutId;
function updateClass() {
element.removeClass('rem-base-large')
element.removeClass('rem-base-medium')
element.removeClass('rem-base-small')
$localStorage.fontSize = $localStorage.fontSize || "rem-base-medium"
element.addClass($localStorage.fontSize)
}
scope.$watch(attrs.myCurrentTime, function(value) {
format = value;
updateClass();
});
element.on('$destroy', function() {
clearInterval(timeoutId);
});
// start the UI update process; save the timeoutId for canceling
timeoutId = setInterval(function() {
updateClass(); // update DOM
}, 1000);
}
return {
link: link
};
})
如果有人能够阐明它为何在Android上工作,但它并不适用于iOS,我会非常感激。或者,如果您有更好的解决方案来实现我的目标并且不要分享,请执行以下操作:)