简体   繁体   English

水平滚动 web 页面

[英]Horizontally scrolling a web page

I have a page that scrolls horizontally left to right.我有一个从左到右水平滚动的页面。 As the user completes the form, the page is scrolled to the left to show the next part of the form.当用户完成表单时,页面向左滚动以显示表单的下一部分。 This is no problem with jQuery. jQuery 没有问题。 The problem is that I want to have the option to have the parent page jump to a specific subpage of the form.问题是我希望可以选择让父页面跳转到表单的特定子页面。 If my code were vertical, this could be easily done with hashtags.如果我的代码是垂直的,则可以使用主题标签轻松完成。 The only other way that I can think of is to pass a GET variable in the querystring and then echo the GET variable to a javascript variable and move the page that way.我能想到的唯一其他方法是在查询字符串中传递 GET 变量,然后将 GET 变量回显到 javascript 变量并以这种方式移动页面。 Is there a better way?有没有更好的办法?

var subpage = '<?php echo $_GET['subpage'] ?>';
if (subpage == 'yes') {
    $('#page_wrapper').css('left', '-2000px');
}

You can still do it with hashtags:您仍然可以使用主题标签来做到这一点:

var subpage = window.location.hash;
if (subpage == '#yes') {
    $('#page_wrapper').css('left', '-2000px');
}

Also you probably want to use scrollLeft to set the horizontal scroll of the page, if you do it the way you're doing it there you'll run some of the page outside of the viewport.此外,您可能希望使用scrollLeft来设置页面的水平滚动,如果您按照您在那里的方式进行操作,您将在视口之外运行一些页面。

$(document.body).scrollLeft(2000);

You can jQuery plugin to move to any part of the webpage using scrollTo.您可以 jQuery 插件使用 scrollTo 移动到网页的任何部分。 Hope it will work for you.希望它对你有用。 http://flesler.blogspot.com/2007/10/jqueryscrollto.html http://flesler.blogspot.com/2007/10/jqueryscrollto.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM