我在div中有一张箭头的图片。这个div固定在非常宽页面的右下角。
如何使用jQuery在每次单击div时向右滚动600px的窗口?(是否可以检测到页面何时不能再向右滚动,并隐藏箭头?)
干杯。
发布于 2011-02-21 08:50:06
使用jquery方法scrollLeft
$(document).ready(function(){
$(window).scrollLeft((Number($(window).scrollLeft())+600)+'px');
});大概是这样的:)
发布于 2011-02-21 09:05:06
尝试如下所示:
var distance = 600;
$("div").click(function() {
$("html:not(:animated), body:not(:animated)").animate(
{scrollLeft: "+="+distance}, 400
);
});jsfiddle这里:http://jsfiddle.net/juXLu/2/
编辑,这里检测您是否在文档http://jsfiddle.net/lukemartin/juXLu/5/的末尾
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");
}
}
);
});发布于 2011-02-21 08:53:56
你可以使用Scrollto插件,
http://plugins.jquery.com/project/ScrollTo
它非常容易使用,只需使用文档即可。然后,您可以创建一个占位符来确定它是否位于页面末尾。只需将占位符放在最后,并计算距离。
https://stackoverflow.com/questions/5061241
复制相似问题