![](/img/trans.png)
[英]How to get the position of screen window of browser when scroll down jquery
[英]jQuery - How to get browser window to scroll horizontal when div is clicked?
我有div中的箭頭圖片。 這個div固定在非常寬的頁面的右下角。
如何在每次單擊div時使用jQuery將窗口向右滾動600px? (並且可以檢測頁面何時無法向右滾動,並隱藏箭頭?)
干杯。
嘗試這樣的事情:
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");
}
}
);
});
使用jquery方法scrollLeft
$(document).ready(function(){
$(window).scrollLeft((Number($(window).scrollLeft())+600)+'px');
});
這樣的東西:)
您可以使用Scrollto插件,
http://plugins.jquery.com/project/ScrollTo
它非常易於使用,只需使用文檔即可。 然后,您可以創建一個占位符,以確定它是否到頁面的末尾。 只需將占位符粘貼在最后,然后計算距離。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.