问题陈述:
我正在使用ng-cordova插件从 Angularjs创建 IOS应用,对于我的项目我正在使用水平滚动条(如滑动),每当我试图选择/取消选择图像时它的响应都会延迟。我使用$ watch()来观察我的$ scope对象的变化。我无法确定问题出在哪里,是否在我的css 我的控制器。请任何人帮我解决问题。
标记:
<div class="wrapper no-copy">
<div class="internal" ng-repeat="pf in printlist"><img class="" ng-click="pf.selectFile = !pf.selectFile ;showCustom($event,pf)" ng-src="{{pf.imagePath}}"><div class="no-copy filedetail"><div style="color:black;margin-left:7px;" class=" no-copy internal font-filedetail">{{pf.filename.substring(0,8)}}..</br>Pages: {{pf.totalPages}}</br>{{pf.releaseCode}}</div><div class="internal filedetailbar"><img style="height:70px;" src="images/beacon/line_icon.png"></div></div>
</div>
</div>
CSS:
.wrapper {
width: 100%;
white-space: nowrap;
overflow-y: hidden;
overflow-x: scroll;
-webkit-overflow-scrolling: touch;
padding: 1rem;
background-color: white;
// Toggle this depending upon whether you want to see the scrollbar
&::-webkit-scrollbar {
display: none;
}
}
.internal {
display: inline;
}
控制器:
$scope.showCustom = function (event, detail) {
console.log('detail')
console.log(detail)
/*$mdDialog.show({
locals: {name: detail},
clickOutsideToClose: true,
scope: $scope,
preserveScope: true,
templateUrl: 'ibprintProcessList/filedetail.html',
controller: function DialogController($scope, $mdDialog, name) {*/
$scope.del = detail;
console.log($scope.del.color)
console.log('*************')
console.log($scope.del)
if (!$scope.del.color) {
$scope.color = false
}
if ($scope.del.selectFile) {
$scope.filestatus = 'selected '
$scope.disabled = false
$scope.isFileSelect = $scope.isFileSelect + 1
$scope.selectfileextension = $scope.del.filename.split('.')
console.log('???????????????')
console.log($scope.selectfileextension[1])
if (($scope.selectfileextension[1] == 'pdf') || ($scope.selectfileextension[1] == 'rtf')) {
$scope.del.imagePath = "./images/beacon/pdf_icon_select.png"
}
else if (($scope.selectfileextension[1] == 'doc') || ($scope.selectfileextension[1] == 'docx')) {
$scope.del.imagePath = "./images/beacon/word_icon_select.png"
}
else if (($scope.selectfileextension[1] == 'xls') || ($scope.selectfileextension[1] == 'xlsx')) {
$scope.del.imagePath = "./images/beacon/xls_icon_select.png"
}
else if (($scope.selectfileextension[1] == 'ppt') || ($scope.selectfileextension[1] == 'pptx')) {
$scope.del.imagePath = "./images/beacon/pp_icon_select.png"
}
else if (($scope.selectfileextension[1] == 'png') || ($scope.selectfileextension[1] == 'jpg') || ($scope.selectfileextension[1] == 'jpeg') || ($scope.selectfileextension[1] == 'bmp') || ($scope.selectfileextension[1] == 'gif') || ($scope.selectfileextension[1] == 'tiff') || ($scope.selectfileextension[1] == 'tif')) {
$scope.del.imagePath = "./images/beacon/image_icon_select.png"
}
}
else {
$scope.disabled = true
$scope.isFileSelect = $scope.isFileSelect - 1
$scope.filestatus = 'unselected '
$scope.selectfileextension = $scope.del.filename.split('.')
if (($scope.selectfileextension[1] == 'pdf') || ($scope.selectfileextension[1] == 'rtf')) {
$scope.del.imagePath = "./images/beacon/pdf_icon.png"
}
else if (($scope.selectfileextension[1] == 'doc') || ($scope.selectfileextension[1] == 'docx')) {
$scope.del.imagePathh = "./images/beacon/word_icon.png"
}
else if (($scope.selectfileextension[1] == 'xls') || ($scope.selectfileextension[1] == 'xlsx')) {
$scope.del.imagePath = "./images/beacon/xls_icon.png"
}
else if (($scope.selectfileextension[1] == 'ppt') || ($scope.selectfileextension[1] == 'pptx')) {
$scope.del.imagePath = "./images/beacon/pp_icon.png"
}
else if(($scope.selectfileextension[1] == 'png') || ($scope.selectfileextension[1] == 'jpg') || ($scope.selectfileextension[1] == 'jpeg') || ($scope.selectfileextension[1] == 'bmp') || ($scope.selectfileextension[1] == 'gif') || ($scope.selectfileextension[1] == 'tiff') || ($scope.selectfileextension[1] == 'tif')){
$scope.del.imagePath = "./images/beacon/image_icon.png"
}
}
/*$scope.closeDialog = function () {
$mdDialog.hide();
//$scope.printNow()
}*/
$scope.del.$digest()
$scope.printlist.$digest()
console.log('Watch function starts')
// $scope.$watch($scope.del, $scope.showCustom);
$scope.$watchGroup(['$scope.del', '$scope.printlist'],$scope.showCustom,true)
console.log('Watch function ends')
}
当用户选择/取消选择 $ scope.showCustom(event,pf)被触发时 pf对象传递给控制器并将pf对象分配给$ scope.del对象
当用户选择/取消选择 $ scope.del.imagepath 保存图像并更改图像源
Referimage:Screen Shot
我尝试了$ watch()和$ watchGroup()函数,它在选择/取消选择时会出现延迟
答案 0 :(得分:2)
只需使用一个使用溢出样式的简单水平滚动条,它将在您的移动应用程序中用作SWIPE。
-webkit-overflow-scrolling: touch;
&::-webkit-scrollbar {
display: none;
}
删除了上面的CSS,因为您正在从网络移植到移动应用。 -webkit-overflow-scrolling用于浏览器。有时,当您将网络应用转换为移动应用时,它可能/可能无效。
而是添加以下CSS:
overflow-y: hidden;
overflow-x: scroll;
width: 500px; // you can change the width size depends on you
white-space: nowrap;