首页 > web前端 > js教程 > js实现页面刷新滚动条位置不变

js实现页面刷新滚动条位置不变

高洛峰
发布: 2016-12-05 09:53:18
原创
1262 人浏览过

今天因为这个问题困扰了很久网上的例子都尝试没效果,后来发现一点原来是内容最外层没有div的原因

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

143

144

145

146

147

148

149

150

151

152

153

154

155

156

157

158

159

160

161

162

163

164

165

166

167

168

169

170

171

172

173

174

175

176

177

178

179

180

181

182

183

184

185

186

187

188

189

190

191

192

193

194

195

196

197

198

199

200

201

202

203

204

205

206

207

208

209

210

211

212

213

214

215

216

217

218

219

220

221

222

223

224

225

226

227

228

229

230

231

232

233

234

235

236

237

238

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="SpotChkDetail.aspx.cs" Inherits="Topevery.DUM.Web.Observer.SpotChkDetail" %>

<script runat="server">

  protected override bool HeaderScriptFilter(Topevery.Framework.Web.Configuration.Script val)

  {

    switch (val.Key)

    {

      case "ajaxpro2.prototype":

      case "ajaxpro2.core":

      case "ajaxpro2.converter":

      case "ajaxpro2.onloading":

      case "ajaxpro2.assembly.AjaxFunction":

      case "my97":

      case "image":

      case "jquery.pagination":

      case "jquery.jqGrid.locale":

      case "jquery.jqGrid":

      case "jquery-load-image":

      case "jquery.validationEngine":

      case "jquery.validationEngine-zh":

      case "WeiBo":

      case "jquery.mousewheel":

      case "jquery.iviewer":

      case "jquery.gallery.singer":

        return true;

      default:

        return base.HeaderScriptFilter(val);

    }

  }

  protected override bool HeaderStyleFilter(Topevery.Framework.Web.Configuration.Style val)

  {

    switch (val.Key)

    {

      case "jqgrid":

      case "jqgrid-grey":

      case "validationEngine":

        return true;

      default:

        return base.HeaderStyleFilter(val);

    }

  }

</script>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

  <title></title>

</head>

<body id="bbdy">

  <form id="form1" runat="server">

    <div>

    <div class="TUI-layout-north">

      <div class="TUI-title">

        <span class="TUI-ico ico-note"></span><strong>抽查</strong>

      </div>

      <div class="" style="float: right; margin-top: -30px; z-index: 99999; position: relative;">

        <object id="WebBrowser" classid="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2" height="0" width="0">

        </object>

        <input type="button" class="TUI-button" value="打 印" onclick="document.all.WebBrowser.ExecWB(6, 1)" id="Button2" />

        <input type="button" class="TUI-button" value="打印预览" onclick="document.all.WebBrowser.ExecWB(7, 1)" />

      </div>

      <div class="TUI-alert">

        <span class="ml10px">抽查时间:<asp:Label ID="lbBeginDate" runat="server" Text="Label"></asp:Label> 

          失效时间:<asp:Label ID="lbEndDate" runat="server" Text="Label"></asp:Label> 

          消息内容:<asp:Label ID="lbContent" runat="server" Text="Label"></asp:Label></span>

        <div style="display: none">

                <asp:Button ID="btnRef" runat="server" OnClick="btnRef_Click" Text="刷新" />

              </div>

      </div>

    </div>

    <div class="TUI-layout-center">

      <div class="TUI-content TUI-h100 TUI-of-auto TUI-align-center">

        <asp:Repeater ID="Repeater1" runat="server" OnItemDataBound="Repeater1_ItemDataBound">

          <%--OnItemCommand="Repeater1_ItemCommand"--%>

          <HeaderTemplate>

            <table class="TUI-grid-list w100" id="observers">

              <tr>

                <th style="width: 150px">巡查员头像

                </th>

                <th style="width: 80px">姓 名

                </th>

                <th style="width: 120px">是否超时

                </th>

                <%--<th style="width: 110px">城管通号码

                </th>

                <th style="width: 110px">城管通版本

                </th>--%>

                <th style="width: 100px">消息状态

                </th>

                <th style="width: 100px">审核状态

                </th>

                <th style="width:150px">审核

                </th>

              </tr>

          </HeaderTemplate>

          <ItemTemplate>

            <tr class="people_title_td">

              <td rowspan="2" valign="middle" style="width: 110px">

                <img id="img_observer_poto" runat="server" height="135" style="border: 1px solid #bababa;" width="100" />

              </td>

              <td style="width: 60px">

                <%# Eval("c_name")%>

                  <asp:HiddenField ID="hfObId" runat="server" Value=&#39;<%# Eval("c_ob_id") %>&#39; />

                <asp:HiddenField ID="hfId" runat="server" Value=&#39;<%# Eval("c_id") %>&#39; />

              </td>

              <td style="width: 100px">

                <%# Eval("c_is_over_time")%>

              </td>

              <%--<td style="width: 110px">

                <%# Eval("c_pda_number")%>

              </td>

              <td style="width: 110px">

                <%# Eval("c_pda_version")%>

              </td>--%>

              <td style="width: 90px">

                <%# Eval("notify_state")%>

              </td>

              <td style="width: 90px">

                <%# Eval("eligible_state")%>

              </td>

              <td style="width:150px;">

                <div style="display:<%# Eval("c_is_eligible").ToString() !="0"?"none":"" %>">

                <%--<asp:LinkButton ID="LinkButton1" runat="server" CommandName="lnk_poto" CommandArgument=&#39;<%# Eval("c_id") %>&#39;>重摄</asp:LinkButton>

                <asp:LinkButton ID="LinkButton2" runat="server" CommandName="lnk_ok" CommandArgument=&#39;<%# Eval("c_id") %>&#39;>合格</asp:LinkButton>

                <asp:LinkButton ID="LinkButton3" runat="server" CommandName="lnk_no" CommandArgument=&#39;<%# Eval("c_id") %>&#39;>不合格</asp:LinkButton>--%>              

                <a href=&#39;#&#39; onclick=&#39;review(<%# Eval("c_id") %>,0,"重摄")&#39; class=&#39;TUI-toolbar-btn&#39;><span></span>重摄</a>

                <a href=&#39;#&#39; id="qualified" onclick=&#39;review(<%# Eval("c_id") %>,1,"合格")&#39; class=&#39;TUI-toolbar-btn&#39;><span></span>合格</a>

                <a href=&#39;#&#39; id="Unqualified" onclick=&#39;review(<%# Eval("c_id") %>,2,"不合格")&#39; class=&#39;TUI-toolbar-btn&#39;><span></span>不合格</a>

                  

                  </div>

              </td>

            </tr>

            <tr class="alt_tr2">

              <td colspan="5" style="height: 160px; text-align: left">

                <table class="choucha-table">

                  <tr>

                    <asp:Repeater ID="rptImg" runat="server">

                      <ItemTemplate>

                        <td>

                          <div class="div_img TUI-notelist-container TUI-gallery choucha-img">

                            <div id=&#39;imge&#39;+&#39;<%#Eval("FileId") %>&#39;>

                                <div class="TUI-gallery-content TUI-gallery-img">

                                  <a title=&#39;点击放大&#39; href="javascript:void(0)"

                                    sourceSrc=&#39;<%#Eval("Imageurl") %>&#39; largeSrc=&#39;<%#Eval("Imageurl") %>&#39;><img src=&#39;<%#Eval("Imagethumbil") %>&#39; /><span><%#Eval("Summary") %></span></a>

                                </div>

                            </div>

                          </div>

                        </td>

                      </ItemTemplate>

                    </asp:Repeater>

                  </tr>

                </table>

              </td>

            </tr>

          </ItemTemplate>

          <FooterTemplate>

            </table>

          </FooterTemplate>

        </asp:Repeater>

        <input type="hidden" id="hdnvalue" runat="server" value="0" /><!----存放scorllTop值-->

      </div>

    </div>

    </div>

    <script type="text/javascript">

      $(document).ready(function () {

        TUILayout("form");

        //LoadImage();

        $(".div_img").gallery({

          gallerySize: { width: 90, height: 120 },

          fullView: "true" //ture为允许点击图像全屏浏览

        });

  

      });

      function LoadImage() {

        var jq_o_list = $("#observers div[@ref_id]");

  

        for (var i = 0 ; i < jq_o_list.length; i++) {

          load_to(jq_o_list[i]);

        }

      }

  

      function load_to(obj) {

        var jq_o = $(obj);

        Topevery.DUM.Web.AjaxFunction.GetEvtDefault(jq_o.attr("ref_id"), function (ajaxResult) {

          var val = ajaxResult.value;

          jq_o.empty();

          jq_o.append(val.Html);

        });

      }

  

      //$("#div_evt_img").gallery({

      //  images: evt_img_list,

      //  thumbSize: { width: 65, height: 60 },//缩略图大小

      //  gallerySize: { width: 380, height: 280 },//画廊图(中间大图)大小

      //  thumbDisplayNum: 4,//缩略图显示数量

      //  scalingSize: { width: 360, height: 260 },//画廊图(中间大图)自动比例缩放最大大小

      //  fullView: "true" //ture为允许点击图像全屏浏览

      //});

  

      function Reminder() {

        NotSelectEvt("已经再次发送消息通知巡查员!");

      }

  

      function review(id, type, content) {

        if (confirmL("确认" + content + "吗?", function () {

            Topevery.DUM.Web.AjaxFunction.ReviewImg(id, type);

            $("#btnRef").click();

  

        })) {

        }

      }

    </script>

      

  </form>

</body>

</html>

<script type="text/javascript">

  window.onbeforeunload = function () {

    var scrollPos;

    if (typeof window.pageYOffset != &#39;undefined&#39;) {

      scrollPos = window.pageYOffset;

    }

    else if (typeof document.compatMode != &#39;undefined&#39; &&

      document.compatMode != &#39;BackCompat&#39;) {

      scrollPos = document.documentElement.scrollTop;

    }

    else if (typeof document.body != &#39;undefined&#39;) {

      scrollPos = document.body.scrollTop;

    }

    document.cookie = "scrollTop=" + scrollPos; //存储滚动条位置到cookies中

  }

  window.onload = function () {

    if (document.cookie.match(/scrollTop=([^;]+)(;|$)/) != null) {

      var arr = document.cookie.match(/scrollTop=([^;]+)(;|$)/); //cookies中不为空,则读取滚动条位置

      document.documentElement.scrollTop = parseInt(arr[1]);

      document.body.scrollTop = parseInt(arr[1]);

    }

  }

    </script>

登录后复制


相关标签:
js
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
javascript - js addClass 无效
来自于 1970-01-01 08:00:00
0
0
0
php调用js并获取js的返回值问题
来自于 1970-01-01 08:00:00
0
0
0
javascript - js代码转python
来自于 1970-01-01 08:00:00
0
0
0
找不到js文件代码
来自于 1970-01-01 08:00:00
0
0
0
js高级教程
来自于 1970-01-01 08:00:00
0
0
0
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板