Home > front end >  The small white technology, great god answers online
The small white technology, great god answers online

Time:09-29

$(' about '). Click (function () {
Var winH=$(window). Height ();
$(' body, HTML). The animate ({
ScrollTop: winH
}, 600, the function () {

})
})
$(' works'). Click (function () {
Var winH=$(window). Height ();
$(' body, HTML). The animate ({
ScrollTop: winH * 2
}, 600, the function () {

})
})
$(' skill '). Click (function () {
Var winH=$(window). Height ();
$(' body, HTML). The animate ({
ScrollTop: winH * 3
}, 600, the function () {

})
})
$(' contavt '). Click (function () {
Var winH=$(window). Height ();
$(' body, HTML). The animate ({
ScrollTop: winH * 4
}, 600, the function () {

})


Asked how the four merged into a similar code

CodePudding user response:

 
; [' about ', 'works',' skill ', 'contavt']. ForEach (function (v, I) {
$(v). Click (function () {
Var winH=$(window). Height ();
$(' body, HTML). The animate ({
ScrollTop: winH * (I + 1)
}, 600, the function () {

})
})
});

CodePudding user response:

[' about ', 'works',' skill ', 'contavt']. ForEach (function (v, I) {
$(v). Click (function () {
Var winH=$(window). Height ();
$(' body, HTML). The animate ({
ScrollTop: winH * (I + 1)
}, 600, the function () {

})
})
});
Remove the first semicolon? thank you

CodePudding user response:

refer to the second floor zhtoad response:
[' about ', 'works',' skill ', 'contavt']. ForEach (function (v, I) {
$(v). Click (function () {
Var winH=$(window). Height ();
$(' body, HTML). The animate ({
ScrollTop: winH * (I + 1)
}, 600, the function () {

})
})
});
Remove the first semicolon? Thank you,


First semicolon is for fault tolerance, when on line didn't write a semicolon is likely to be the [] as a subscript of an array variable
  • Related