我有这个input元素:
<input type="text" class="textfield" value="" id="subject" name="subject">
Run Code Online (Sandbox Code Playgroud)
然后我有一些其他元素,如其他文本输入,textareas等.
当用户点击它input时#subject,页面应滚动到页面的最后一个元素,并带有漂亮的动画.它应该是一个滚动到底部而不是顶部.
页面的最后一项是一个submit按钮,其中包含#submit:
<input type="submit" class="submit" id="submit" name="submit" value="Ok, Done.">
Run Code Online (Sandbox Code Playgroud)
动画不应该太快,应该是流畅的.
我正在运行最新的jQuery版本.我更喜欢不安装任何插件,但使用默认的jQuery功能来实现这一点.
我想让浏览器将页面滚动到给定的锚点,只需使用JavaScript即可.
我在HTML代码中指定了一个name或id属性:
<a name="anchorName">..</a>
Run Code Online (Sandbox Code Playgroud)
要么
<h1 id="anchorName2">..</h1>
Run Code Online (Sandbox Code Playgroud)
我希望通过导航获得与您相同的效果http://server.com/path#anchorName.应滚动页面,使锚点靠近页面可见部分的顶部.
我的 css 属性有问题scroll-margin-top(滚动到页面上的元素时添加偏移量)。它并不适用于所有情况,特别是在这种情况下:当 的元素scroll-margin-top位于 的容器内时overflow: hidden。
可能是什么原因?有解决方法吗?
如何在wordpress gutenberg编辑器中将新插入的块滚动到视图中?
我正在创建块
const nextBlock = createBlock( 'core/paragraph' );
wp.data.dispatch( 'core/editor' ).insertBlock( nextBlock );
//scroll the block into the view
Run Code Online (Sandbox Code Playgroud)
我还看到古登堡(Gutenberg)dom-scroll-into-view像在这里那样使用软件包。
他们的文件说:
var scrollIntoView = require('dom-scroll-into-view');
scrollIntoView(source,container,config);
Run Code Online (Sandbox Code Playgroud)
但是如何使它在我的情况下起作用,如何获取源和容器DOM元素?
javascript wordpress reactjs wordpress-gutenberg gutenberg-blocks
我有一个网页,我想滚动到该网页上的某个元素。
通过使用该部分可以正常工作scrollIntoView;但我想在元素(20px或其他内容)上方添加一些空间
我目前正在做这样的事情:
const moveToBlue = () => {
const blue = document.getElementById('blue')
blue.scrollIntoView({ behavior: 'smooth', block: 'start', inline: 'start'});
};
Run Code Online (Sandbox Code Playgroud)
这可能吗?