简体   繁体   English

jQuery scrollTo插件无法将屏幕滚动到div,为什么?

[英]jQuery scrollTo plugin to scroll screen to div wouldn't work, why?

I am working on a web application, whose mock-up page can now be found at: our server 我正在使用一个Web应用程序,其模拟页面现在可以在以下位置找到: 我们的服务器

If you click on the blue title "step1" and then choose the option of "delivery to address", a form will show up using jQuery ajax load. 如果单击蓝色标题“ step1”,然后选择“传递到地址”选项,则将使用jQuery ajax加载显示表单。 No problem for this. 没问题。 Click on the "venue" radio button will take you to another form, no problem for this as well. 单击“地点”单选按钮将带您进入另一种形式,对此也没有问题。

If you scroll down a bit, you can see a textarea, top of that you can see a link called "what's this?". 如果向下滚动一点,您将看到一个文本区域,最上方可以看到一个名为“这是什么?”的链接。 Click on it and the textarea shall be filled with sample words. 单击它,文本区域应填充示例词。

The problem is, after clicking on the link, the webpage automatically scrolls to the top section. 问题是,单击链接后,网页会自动滚动到顶部。 What I want is to keep the textarea to the center of screen after link is clicked. 我想要的是单击链接后将文本区域保持在屏幕中央。

I am trying to use a jQuery plugin called "scrollTo", which can be found here 我正在尝试使用一个名为“ scrollTo”的jQuery插件,可以在此处找到

From its demo page I can tell is what I want. 从其演示页面中,我可以看出我想要什么。 And here is my code to try using it: 这是我的代码尝试使用它:

function reloadDeliveryForm()
{
$('#deliveryForm').load('./ajax/deliveryToVenueForm.html', 
           function(response,     status, xhr) 
{
    if (status == "error") 
    {
        $.prompt("Sorry but there was an error, please try again.<br />" +
                 "If same error persists, please report to webmaster.");
    }
    else    //deliveryForm loaded successfully
    {
        validateDeliveryForm();
        $("#delivery_special").elastic();
        $('#special_conditions_tip').click(function()
        {
            console.log("start filling");
            fillTextareaWithExample();
            console.log("end filling");
            $.scrollTo('#delivery_special');
            console.log("end scrolling");
        });
    }
});

} }

From Firebug output I can tell the scrollTo function is called, but doesn't work. 从Firebug的输出中,我可以知道scrollTo函数已被调用,但不起作用。 I've switched jQuery back to version 1.3.2, which is used on the demo page of the plugin, but that wouldn't help, either. 我将jQuery切换回了版本1.3.2,该版本在插件的演示页面上使用,但这也无济于事。

Is there a problem with my coding? 我的编码有问题吗? Which technique would you use to resolve this problem? 您将使用哪种技术解决此问题?

Any suggestion is much appreciated. 任何建议深表感谢。

Approx. line 112 of your custom.js, change this 您custom.js的第112行,请更改此

$('#special_conditions_tip').click(function()
{
    console.log("start filling");
    fillTextareaWithExample();
    console.log("end filling");
    $.scrollTo('#delivery_special');
    console.log("end scrolling");
}); 

to this 对此

$('#special_conditions_tip').click(function(event)
{
    event.preventDefault();
    console.log("start filling");
    fillTextareaWithExample();
    console.log("end filling");
    $.scrollTo('#delivery_special');
    console.log("end scrolling");
}); 

.preventDefault() prevents the browsers action from taking place. .preventDefault()阻止浏览器执行操作。

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

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