簡體   English   中英

jQuery scrollTo插件無法將屏幕滾動到div,為什么?

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

我正在使用一個Web應用程序,其模擬頁面現在可以在以下位置找到: 我們的服務器

如果單擊藍色標題“ step1”,然后選擇“傳遞到地址”選項,則將使用jQuery ajax加載顯示表單。 沒問題。 單擊“地點”單選按鈕將帶您進入另一種形式,對此也沒有問題。

如果向下滾動一點,您將看到一個文本區域,最上方可以看到一個名為“這是什么?”的鏈接。 單擊它,文本區域應填充示例詞。

問題是,單擊鏈接后,網頁會自動滾動到頂部。 我想要的是單擊鏈接后將文本區域保持在屏幕中央。

我正在嘗試使用一個名為“ scrollTo”的jQuery插件,可以在此處找到

從其演示頁面中,我可以看出我想要什么。 這是我的代碼嘗試使用它:

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");
        });
    }
});

}

從Firebug的輸出中,我可以知道scrollTo函數已被調用,但不起作用。 我將jQuery切換回了版本1.3.2,該版本在插件的演示頁面上使用,但這也無濟於事。

我的編碼有問題嗎? 您將使用哪種技術解決此問題?

任何建議深表感謝。

您custom.js的第112行,請更改此

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

對此

$('#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()阻止瀏覽器執行操作。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM