在web浏览器中向下滚动页面
本文关键字:滚动 web 浏览器 | 更新日期: 2023-09-27 18:14:22
我有一个web浏览器在我的windows窗体,我希望它自动向下滚动页面。现在我输入
this.webBrowser.Document.Window.ScrollTo(0, int.MaxValue);
但是当我启动我的应用程序,webBrowser不滚动。为什么?
可以了!!)))
class KeyHandle
{
private static Int32 WM_KEYDOWN = 0x100;
private static Int32 WM_KEYUP = 0x101;
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("user32.dll", SetLastError = true)]
static extern bool PostMessage(IntPtr hWnd, int Msg, System.Windows.Forms.Keys wParam, int lParam);
public static void SendKey(IntPtr hWnd, System.Windows.Forms.Keys key)
{
PostMessage(hWnd, WM_KEYDOWN, key, 0);
}
}
调用方法:
KeyHandle.SendKey(this.webBrowser.Handle, Keys.PageDown);
脚本:
function top() {
document.getElementById( 'top' ).scrollIntoView();
};
function bottom() {
document.getElementById( 'bottom' ).scrollIntoView();
window.setTimeout( function () { top(); }, 2000 );
};
bottom();
HTML: <div id="top">top</div>
<div id="bottom">bottom</div>
$(document).ready(function () {
var myInterval = false;
myInterval = setInterval(AutoScroll, 2000);
function AutoScroll() {
var iScroll = $(window).scrollTop();
iScroll = iScroll + 500;
$('html, body').animate({
scrollTop: iScroll
}, 1000);
}
$(window).scroll(function () {
var iScroll = $(window).scrollTop();
if (iScroll == 0) {
myInterval = setInterval(AutoScroll, 2000);
}
if (iScroll + $(window).height() == $(document).height()) {
clearInterval(myInterval);
}
});
});