#include <iostream>
class aid {
public:
using aid_t = std::string;
void setaid(const std::string& s) {
aid_ = s;
}
const aid_t& getaid() const {
return aid_;
}
private:
aid_t aid_;
};
class c {
public:
using c_t = std::string;
void setc(const aid::aid_t& aid_val) {
if (aid_val.size() < 4)
c_ = "yeah";
else
c_ = aid_val + aid_val;
}
const c_t& getc() {
return c_;
}
private:
c_t c_;
};
template<typename ...Columns>
class table : public Columns... {
};
template <typename... Columns>
void f(table<Columns...>& t) {
t.setaid("second");
std::cout << t.getaid() << "\n";
}
void f2(table<aid>& t) {
t.setaid("third");
std::cout << t.getaid() << "\n";
}
int main() {
table<aid, c> tb;
tb.setaid("first");
std::cout << tb.getaid() << " " << "\n";
// f<c>(tb); // (1) doesnt compile, that seem obvious
f<aid>(tb); // (2) works?
f(tb); // (3) works too -- template parameter deduction
// f2(tb); // (4) doesnt work? worked with (2)...
}
答案 0 :(得分:1)
您可以使用以下代码添加转换持续时间。
function topFunction() {
currentYOffset = self.pageYOffset;
initYOffset = currentYOffset;
var intervalId = setInterval(function(){
currentYOffset -= initYOffset*0.05;
document.body.scrollTop = currentYOffset ;
document.documentElement.scrollTop = currentYOffset;
if(self.pageYOffset == 0){
clearInterval(intervalId);
}
}, 20);
}
您可以通过编辑间隔值来设置过渡的平滑度。我把它设置为20。
答案 1 :(得分:0)
这是一个使用jQuery.animate函数的jQuery解决方案。
该功能使您能够更改动画时间,以及应用动画的选择器,以便您也可以滚动其他元素。
/**
* Scroll to a given point on the page with animation
*
* @param {int} scrollValue - The top position to scroll to
* @param {int} [animationTime] - Speed of the animation (in milliseconds)
* @param {string} [selector] - Which element to scroll. By default, it is the html/body
*/
function animateScrollTo(scrollValue, animationTime, selector){
if(typeof animationTime === "undefined"){
animationTime = 520;
}
if(typeof selector === "undefined"){
selector = "html, body";
}
jQuery(selector).animate({scrollTop: scrollValue}, animationTime);
}
答案 2 :(得分:0)
body {
scroll-behavior: smooth;
}
只需使用此属性,document.body.scrollTop = 0
就可以流畅地进行过渡/动画。
答案 3 :(得分:0)