滚动到jQuery-Textarea的顶部

我正在尝试向我的jQuery移动应用程序添加“更改日志”。 如果出现错误,用户应该有能力,看看出了什么问题。 因此我实现了一个带有textarea的弹出窗口(见下面的代码)

 

Logg-Einträge:

OK

此popUp充满了数据,并在单击特定按钮时打开:

 $('#showLog').click(function() { $("#popupDialog").popup("close"); // populate the textArea with the text $("#popupTextArea").text(sessionStorage.getItem("logStack")); // open popUp after a specific time setTimeout( function(){$('#popupLog').popup('open'); }, 1000 ); }); 

到目前为止,所有function都正常运行。 问题是:当用户在textarea中向下滚动时,关闭popUp并重新打开它,滚动条的位置仍然相同 – 例如用户向下滚动到底部,关闭popUp并重新打开它 – popUp将位于textarea agein的底部。 但是当我再次打开popUp时,我想总是把它放在textarea的顶端。 为了实现这一点,我在这个popUp中实现了一个“Ok”-Button,如下所示,它关闭popUp并将scrollingTop设置为0:

 $('#btn_textArea').click(function() { // Setting position of the textArea to "0" -> But doesn't work..... $('#popupTextArea').scrollTop(0); ); }); 

我在这一点上有点兴奋,因为textArea的外观仍然相同。 我需要刷新还是什么? 我会非常感谢每一个帮助….

您可以使用popupbeforeposition事件来操作textarea的scrollTop属性:

 $(document).ready(function(){ $("#exampleWindow").on("popupbeforeposition", function(evt, ui){ $(this).find("textarea").scrollTop(0); }); }); 

在这里你有一个带有一个例子的jsFiddle ,用一些文本填充textarea并测试在滚动后打开弹出窗口: http : //jsfiddle.net/elchininet/eBp7S/