我在使用我的webapp的前端时遇到了一些问题。有几个问题:
如果时间过长,我需要剪切文字,所以
.suggestion-box-text {white-space:nowrap;溢出:隐藏;
文本溢出:省略号; }
但是我不能在Chrome中使用滚动,只能使用按键。 2.无论我使用什么,Safari都会记住列表中最后选择的项目,下次使用选择时,它会从它开始,而不是从第一个元素开始。
在FireFox中也无法正常工作,当做同样的事情来剪切太长的文本时,滚动仍然有效,但是当我用键移动时,列表不会滚动。
有没有任何已知的方法来解决这个问题?或者只是尝试一下好运,直到找到合适的组合?
HTML文件
<div class="navbar-container container-fluid">
<div class="" id="site-navbar-search">
<form id="originalSearch" role="search" ng-submit="query()">
<div class="form-group" style="margin: 15px 0px 0px 0px">
<div class="input-search">
<speech class=""></speech>
<input id="questionForInput" type="text"
ng-change="ask.getsuggestions()" autocomplete="off"
ng-model="ask.term" class="form-control bg-dark"
placeholder="Ask ..." ng-keydown="key($event)"/>
<select id="suggestionSelection" class="suggestion-box
list-group2 bg-dark" ng-keydown="key2($event)"
multiple="multiple"ng-model="ask.term">
<option class="list-group-item2 suggestion-box-text bg-dark"
ng-repeat="command in ask.suggestions">
{{command.statement}}
</option>
</select>
<button type="submit" style="visibility: hidden; display:none"></button>
</div>
</div>
</form>
</div>
</div>
CSS FILE
.suggestion-box {
overflow: auto;
overflow: -moz-scrollbars-auto;
position: absolute;
z-index: 1;
width:100%;
visibility: hidden;
border-radius: 0px 0px 18px 18px;
outline: none;
}
.suggestion-box-text {
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
@supports (overflow:-webkit-marquee) and (justify-content:inherit)
{
.suggestion-box {
padding-left: 15px;
}
}
body{
scrollbar-base-color: #C0C0C0;
scrollbar-base-color: #C0C0C0;
scrollbar-3dlight-color: #C0C0C0;
scrollbar-highlight-color: #C0C0C0;
scrollbar-track-color: #EBEBEB;
scrollbar-arrow-color: black;
scrollbar-shadow-color: #C0C0C0;
scrollbar-dark-shadow-color: #C0C0C0;
}
::-webkit-scrollbar { width: 0px; height: 0px;}
::-webkit-scrollbar-button { background-color: #666; }
::-webkit-scrollbar-track { background-color: #999;}
::-webkit-scrollbar-track-piece { background-color: #ffffff;}
::-webkit-scrollbar-thumb { height: 0px; background-color: #666; border-radius: 0px;}
::-webkit-scrollbar-corner { background-color: #999;}}
::-webkit-resizer { background-color: #666;}
也是JS文件的一部分
$scope.key = function($event){
if ($event.keyCode == 40) {
$('#suggestionSelection').focus();
$('#suggestionSelection').focus();
//$("select#suggestionSelection").prop('selectedIndex', -1);
//$("#suggestionSelection")[0].selectedIndex = -1;
}
else if($event.keyCode == 27) {
$('#suggestionSelection').css('visibility', 'hidden');
$('#questionForInput').css('border-radius', '200px 200px 200px 200px');
}
}
$scope.key2 = function($event){
console.log($event.keyCode);
if ($event.keyCode == 38) {
if($('#suggestionSelection')[0].selectedIndex == -1 || $('#suggestionSelection')[0].selectedIndex == 0) {
$('#questionForInput').focus();
$('#suggestionSelection').css('visibility', 'hidden');
$('#questionForInput').css('border-radius', '200px 200px 200px 200px');
}
}
else if($event.keyCode == 27 || $event.keyCode == 13) {
$('#questionForInput').focus();
$('#suggestionSelection').css('visibility', 'hidden');
$('#questionForInput').css('border-radius', '200px 200px 200px 200px');
}
}
答案 0 :(得分:1)
最好使用ngOptions指令(它比<option>
上的ng-repeat快得多
https://docs.angularjs.org/api/ng/directive/ngOptions