sách gpt4 ai đã đi

javascript - 如何自动滚动到列表中最后插入的值(非底部)。[[注 :List is Sorted]]

In lại 作者:行者123 更新时间:2023-11-30 14:10:35 25 4
mua khóa gpt4 Nike

我正在尝试显示数组中的动漫列表。我已经使用“oredrby”过滤器对列表进行了排序。每次添加新行时,我都想自动滚动到列表中最后插入的行。请注意,我不想自动滚动到列表底部。这是

DEMO

演示我的问题。



Angular App

thân hình{
font-family: Verdana;
font-weight: đậm;
hiển thị: flex;
justify-content: center;
overflow: auto;
}
div{
width: 100%;
}
li{
vị trí: tương đối;
animation: drop 0.7s;
cursor: pointer;
}
@keyframes drop{
0%{
height: 0;
box-shadow: 0 -5px 10px;
}
}
ul{
căn chỉnh văn bản: ở giữa;
lề: 0;
đệm: 0;
margin-bottom: 0px;
font-size: 40px;
background-color: orange;
list-style-type: none;
scroll-behavior:
/* height: 75%; */

}
li:nth-child(odd){
hiển thị: flex;
justify-content: center;
align-items: center;
font-size: 40px;
chiều cao: 50px;
background-color: white;
transition: all 0.3s;
}
li:nth-child(even){
hiển thị: flex;
justify-content: center;
align-items: center;
font-size: 40px;
chiều cao: 50px;
background-color: orange;
transition: all 0.3s;
}
li:nth-child(odd) span{
vị trí: tuyệt đối;
hiển thị: khối;
right: 0px;
chiều rộng: 50px;
height: inherit;
background-color: #ff3333;
}
li:nth-child(even) span{
vị trí: tuyệt đối;
hiển thị: khối;
right: 0px;
chiều rộng: 50px;
height: inherit;
background-color: white;
}
li:hover{
box-shadow: 0px -10px 30px;
height: 80px;
font-size: 60px;
}
hình thức{
/* height: 100px; */
bottom:0;
position: sticky;
/* width:100%; */
background-color: #081327;
color: white;
font-size: 40px;
justify-content: center;
align./-items:center;
}
.error{
hiển thị: flex;
opacity: 1;
justify-content: center;
align-items: center;
font-size: 40px;
chiều cao: 50px;
background-color: black;
color: #ff3333;
z-index: 2;
animation: show 0.7s;
}
.error span{

vị trí: tuyệt đối;
hiển thị: flex;
justify-content: center;
align-items: center;
cursor: pointer;
right:0px;
chiều rộng: 50px;
height: inherit;
background-color: lightblue;
color: #ff3333;
transition:all 0.5s;
}
.error span:hover{
background-color: red;
color: black;
}
li span{
vị trí: tuyệt đối;
transition: background-color 0.3s;
right:0px;
cursor: pointer;
}
li span:hover{
background-color: red;
}

form input{
border: 0;
height: 100px;
width:500px;
font-weight: đậm;
font-size:40px;
căn chỉnh văn bản: ở giữa;
font-family: Verdana;
border-top-left-radius: 10px;
border-bottom-left-radius: 10px;
box-shadow: 10px -10px 30px;
}
form button{
border: 0;
height: 100px;
width:300px;
font-size:40px;
margin-bottom:20px;
font-family: Verdana;
font-weight: đậm;
background-color: #ff5413;
border-top-right-radius: 10px;
border-bottom-right-radius: 10px;
box-shadow: 10px -10px 30px;
}

@keyframes show{
/* 20%{
background-color: #1c1c1c;
}
40%{
background-color: black;
}
60%{
background-color: #1c1c1c;
}
80%{
background-color: black;
}
100%{
background-color: #1c1c1c;
} */
0%{

transform-origin: center;
height: 0px;
width: 0px;
font-size: 0px;
}
100%{
chiều cao: 50px;
font-size: 40px;
transform-origin: center;
transform: rotateX(360deg);
}
}
#text{
hiển thị: flex;
vị trí: tuyệt đối;
justify-content: center;
align-items: center;
height: 100%;
position: fixed;
}
#textinfo{
hiển thị: flex;
vị trí: tương đối;
border-radius: 15px;
font-size:40px;
border: solid black 5px;
justify-content: center;
align-items: center;
chiều cao: 200px;
căn chỉnh văn bản: ở giữa;
min-width:400px;
overflow: hidden;
width: auto;
background-color: white;
animation:hello 0.5s;

}


@keyframes hello{
0%{
height:0px;
font-size:0px;
}
100%{
height:200px;
font-size:40px;
}

}
#textinfo span{
vị trí: tuyệt đối;
top: 10px;
right: 10px;
animation: pop 1.4s;
cursor: pointer;
/* animation-delay: 0.9s; */
}
@keyframes pop{
0%{

transform:translateY(-1000px);
}
50%{
transform:translateY(0px);
transform: rotateY(0deg);
}
100%{
transform: rotateY(1turn);
}
}

/* #description{
height:200px;
animation:flow 5s;
} */
/* @keyframes flow{
0%{
height:0px;
}
100%{
height:200px;
}
} */






    Anime List

  • {{x}}
    ×



Anime Exists×

Enter New Anime


<>
type="submit">Add Anime






{{name}}
×




var app = angular.module('AngularApp', []);
app.controller('AngularAppCtrl', function ($scope, $location, $http, $anchorScroll) {
//For fetching data from json
/* $http.get('anime.json').then(function(response){
$scope.anime = response.data.animes;
});*/

$scope.anime = ['Dragon Ball Z', 'One Punch Man', 'Naruto', 'One Piece', 'Yu Yu Hakusho', 'Tokyo Ghoul', 'Pokemon', 'Cowboy Bebop'];
$scope.addAnime = function () {
if (!$scope.newanime) { return; }
if ($scope.anime.indexOf($scope.newanime) == -1) {
/*var split = $scope.newanime.split(':');
$scope.anime.push({'anime': split[0],'hero':split[1]});*/
$scope.anime.push($scope.newanime);
$scope.newanime = "";
$scope.existError = false;
$location.hash('c');
$anchorScroll();
}
else {
$scope.existError = true;
}
};
$scope.removeErr = function () {
$scope.existError = false;
};
$scope.removeAnime = function (x) {
$scope.anime.splice(x, 1);
};
$scope.checkAnime = function () {
if ($scope.anime.indexOf($scope.newanime) == -1) {
$scope.existError = false;
}
else {
$scope.existError = true;
}
};
/*$scope.info = function (x,details) {
$scope.infoyes = true;
$scope.name = x;
$scope.inform = details;

};*/
$scope.info = function (x) {
$scope.infoyes = true;
$scope.name = x;

};
$scope.removeInfo = function () {
$scope.infoyes = false;
};
$scope.getIndex = function (x) {
return $scope.anime.indexOf(x);
}
});








Angular App

thân hình{
font-family: Verdana;
font-weight: đậm;
hiển thị: flex;
justify-content: center;
overflow: auto;
}
div{
width: 100%;
}
li{
vị trí: tương đối;
animation: drop 0.7s;
cursor: pointer;
}
@keyframes drop{
0%{
height: 0;
box-shadow: 0 -5px 10px;
}
}
ul{
căn chỉnh văn bản: ở giữa;
lề: 0;
đệm: 0;
margin-bottom: 0px;
font-size: 40px;
background-color: orange;
list-style-type: none;
scroll-behavior:
/* height: 75%; */

}
li:nth-child(odd){
hiển thị: flex;
justify-content: center;
align-items: center;
font-size: 40px;
chiều cao: 50px;
background-color: white;
transition: all 0.3s;
}
li:nth-child(even){
hiển thị: flex;
justify-content: center;
align-items: center;
font-size: 40px;
chiều cao: 50px;
background-color: orange;
transition: all 0.3s;
}
li:nth-child(odd) span{
vị trí: tuyệt đối;
hiển thị: khối;
right: 0px;
chiều rộng: 50px;
height: inherit;
background-color: #ff3333;
}
li:nth-child(even) span{
vị trí: tuyệt đối;
hiển thị: khối;
right: 0px;
chiều rộng: 50px;
height: inherit;
background-color: white;
}
li:hover{
box-shadow: 0px -10px 30px;
height: 80px;
font-size: 60px;
}
hình thức{
/* height: 100px; */
bottom:0;
position: sticky;
/* width:100%; */
background-color: #081327;
color: white;
font-size: 40px;
justify-content: center;
align./-items:center;
}
.error{
hiển thị: flex;
opacity: 1;
justify-content: center;
align-items: center;
font-size: 40px;
chiều cao: 50px;
background-color: black;
color: #ff3333;
z-index: 2;
animation: show 0.7s;
}
.error span{

vị trí: tuyệt đối;
hiển thị: flex;
justify-content: center;
align-items: center;
cursor: pointer;
right:0px;
chiều rộng: 50px;
height: inherit;
background-color: lightblue;
color: #ff3333;
transition:all 0.5s;
}
.error span:hover{
background-color: red;
color: black;
}
li span{
vị trí: tuyệt đối;
transition: background-color 0.3s;
right:0px;
cursor: pointer;
}
li span:hover{
background-color: red;
}

form input{
border: 0;
height: 100px;
width:500px;
font-weight: đậm;
font-size:40px;
căn chỉnh văn bản: ở giữa;
font-family: Verdana;
border-top-left-radius: 10px;
border-bottom-left-radius: 10px;
box-shadow: 10px -10px 30px;
}
form button{
border: 0;
height: 100px;
width:300px;
font-size:40px;
margin-bottom:20px;
font-family: Verdana;
font-weight: đậm;
background-color: #ff5413;
border-top-right-radius: 10px;
border-bottom-right-radius: 10px;
box-shadow: 10px -10px 30px;
}

@keyframes show{
/* 20%{
background-color: #1c1c1c;
}
40%{
background-color: black;
}
60%{
background-color: #1c1c1c;
}
80%{
background-color: black;
}
100%{
background-color: #1c1c1c;
} */
0%{

transform-origin: center;
height: 0px;
width: 0px;
font-size: 0px;
}
100%{
chiều cao: 50px;
font-size: 40px;
transform-origin: center;
transform: rotateX(360deg);
}
}
#text{
hiển thị: flex;
vị trí: tuyệt đối;
justify-content: center;
align-items: center;
height: 100%;
position: fixed;
}
#textinfo{
hiển thị: flex;
vị trí: tương đối;
border-radius: 15px;
font-size:40px;
border: solid black 5px;
justify-content: center;
align-items: center;
chiều cao: 200px;
căn chỉnh văn bản: ở giữa;
min-width:400px;
overflow: hidden;
width: auto;
background-color: white;
animation:hello 0.5s;

}


@keyframes hello{
0%{
height:0px;
font-size:0px;
}
100%{
height:200px;
font-size:40px;
}

}
#textinfo span{
vị trí: tuyệt đối;
top: 10px;
right: 10px;
animation: pop 1.4s;
cursor: pointer;
/* animation-delay: 0.9s; */
}
@keyframes pop{
0%{

transform:translateY(-1000px);
}
50%{
transform:translateY(0px);
transform: rotateY(0deg);
}
100%{
transform: rotateY(1turn);
}
}

/* #description{
height:200px;
animation:flow 5s;
} */
/* @keyframes flow{
0%{
height:0px;
}
100%{
height:200px;
}
} */






    Anime List

  • {{x}}
    ×



Anime Exists×

Enter New Anime


<>
type="submit">Add Anime






{{name}}
×




var app = angular.module('AngularApp', []);
app.controller('AngularAppCtrl', function ($scope, $location, $http, $anchorScroll) {
//For fetching data from json
/* $http.get('anime.json').then(function(response){
$scope.anime = response.data.animes;
});*/

$scope.anime = ['Dragon Ball Z', 'One Punch Man', 'Naruto', 'One Piece', 'Yu Yu Hakusho', 'Tokyo Ghoul', 'Pokemon', 'Cowboy Bebop'];
$scope.addAnime = function () {
if (!$scope.newanime) { return; }
if ($scope.anime.indexOf($scope.newanime) == -1) {
/*var split = $scope.newanime.split(':');
$scope.anime.push({'anime': split[0],'hero':split[1]});*/
$scope.anime.push($scope.newanime);
$scope.newanime = "";
$scope.existError = false;
$location.hash('c');
$anchorScroll();
}
else {
$scope.existError = true;
}
};
$scope.removeErr = function () {
$scope.existError = false;
};
$scope.removeAnime = function (x) {
$scope.anime.splice(x, 1);
};
$scope.checkAnime = function () {
if ($scope.anime.indexOf($scope.newanime) == -1) {
$scope.existError = false;
}
else {
$scope.existError = true;
}
};
/*$scope.info = function (x,details) {
$scope.infoyes = true;
$scope.name = x;
$scope.inform = details;

};*/
$scope.info = function (x) {
$scope.infoyes = true;
$scope.name = x;

};
$scope.removeInfo = function () {
$scope.infoyes = false;
};
$scope.getIndex = function (x) {
return $scope.anime.indexOf(x);
}
});



1 Câu trả lời

您应该考虑使用 Javascript 方法 element.scrollIntoView();

可能是这样的:

$scope.addAnime = function() {
if (!$scope.newanime) {
newanime.scrollIntoView();
return;
}

关于javascript - 如何自动滚动到列表中最后插入的值(非底部)。[[注 :List is Sorted]],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54531771/

25 4 0
行者123
Hồ sơ cá nhân

Tôi là một lập trình viên xuất sắc, rất giỏi!

Nhận phiếu giảm giá Didi Taxi miễn phí
Mã giảm giá Didi Taxi
Giấy chứng nhận ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com