Javascript jQuery-单击div时如何使浏览器窗口水平滚动?
我在一个div中有一个箭头的图片。这个div固定在非常宽的页面的右下角 如何使用jQuery在每次单击div时向右滚动窗口600px?(是否可以检测页面何时无法向右滚动并隐藏箭头?)Javascript jQuery-单击div时如何使浏览器窗口水平滚动?,javascript,jquery,html,css,scroll,Javascript,Jquery,Html,Css,Scroll,我在一个div中有一个箭头的图片。这个div固定在非常宽的页面的右下角 如何使用jQuery在每次单击div时向右滚动窗口600px?(是否可以检测页面何时无法向右滚动并隐藏箭头?) 干杯。使用jquery方法向左滚动 $(document).ready(function(){ $(window).scrollLeft((Number($(window).scrollLeft())+600)+'px'); }); 类似于:)您可以使用Scrollto插件 它真的很容易使用,只需使用文
干杯。使用jquery方法向左滚动
$(document).ready(function(){
$(window).scrollLeft((Number($(window).scrollLeft())+600)+'px');
});
类似于:)您可以使用Scrollto插件
它真的很容易使用,只需使用文档即可。然后,您可以创建一个占位符来确定它是否位于页面的末尾。只需将占位符粘贴在最末端,然后计算距离。尝试以下方法:
var distance = 600;
$("div").click(function() {
$("html:not(:animated), body:not(:animated)").animate(
{scrollLeft: "+="+distance}, 400
);
});
请点击此处:
[编辑]
这是检测你是否在文档的末尾
我会设法想出一些代码来帮你,但我现在有点忙。
var distance = 600,
docWidth = $(document).width(),
scrollPos;
// click handler
$("div").click(function() {
// animate
$("html:not(:animated), body:not(:animated)").animate(
// amount to scroll
{scrollLeft: "+=" + distance},
// scroll speed (ms)
400,
// callback function
function(){
// check our scroll position
scrollPos = $(window).width() + $(window).scrollLeft();
// if it equals the doc width, we're at the end
if(docWidth === scrollPos) {
$("div").text("End of the line");
}
}
);
});