JQuery method to return the Top Effect

Source: Internet
Author: User

JQuery method to return the Top Effect

This example describes how jQuery returns the top result. Share it with you for your reference. The specific implementation method is as follows:

1. First, the CSS style:

?

1

2

3

4

5

6

7

/* Updown */

# Shangxia {position: fixed; top: 83%; right: 42%; margin-right:-543px; display: block; _ display: none}

# Shang, # comt, # xia {background: url (.. /images/sprite.png) no-repeat; position: relative; cursor: pointer; height: 25px; width: 29px; margin: 10px 0 0}

# Shang {background-position: 0-308px} # comt {background-position: 0-338px; height: 32px}

# Xia {background-position: 0-376px}

# Comt: hover {background-position:-31px-338px} # shang: hover {background-position:-31px-308px}

# Xia: hover {background-position:-31px-376px}

2. jquery Code: (introduce the jQuery core library)

Copy the Code as follows:

/* Updown */

JQuery (document). ready (function ($) {$ body = (window. opera )? (Document. compatMode = "CSS1Compat "? $ ("Html"): $ ("body"): $ ("html, body"); $ ("# shang "). mouseover (function () {up ()}). mouseout (function () {clearTimeout (fq )}). click (function () {$ body. animate ({scrollTop: 0}, 400)}); $ ("# xia "). mouseover (function () {dn ()}). mouseout (function () {clearTimeout (fq )}). click (function () {$ body. animate ({scrollTop: $ (document ). height ()}, 400)}); $ ("# comt "). click (function () {$ body. animate ({scrollTop: $ ("# comments "). offset (). top }, 400)}) ;}; function up () {$ wd = jQuery (window); $ wd. scrollTop ($ wd. scrollTop ()-1); fq = setTimeout ("up ()", 50)}; function dn () {$ wd = jQuery (window); $ wd. scrollTop ($ wd. scrollTop () + 1); fq = setTimeout ("dn ()", 50 )};

3. Reference page:

?

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

<! Doctype html public "-// W3C // dtd html 4.01 Transitional // EN">

<Html>

<Head>

<Base href = "<% = basePath %>">

<Title> My JSP 'index. jsp 'starting page </title>

<Meta http-equiv = "pragma" content = "no-cache">

<Meta http-equiv = "cache-control" content = "no-cache">

<Meta http-equiv = "expires" content = "0">

<Meta http-equiv = "keywords" content = "keyword1, keyword2, keyword3">

<Meta http-equiv = "description" content = "This is my page">

<! --

<Link rel = "stylesheet" type = "text/css" href = "styles.css">

-->

<Style type = "text/css">

/* Updown */

# Shangxia {position: fixed; top: 60%; right: 50%; margin-right:-543px; display: block; _ display: none}

# Shang, # comt, # xia {background: url (images/sprite.png) no-repeat; position: relative; cursor: pointer; height: 25px; width: 29px; margin: 10px 0 0}

# Shang {background-position: 0-308px} # comt {background-position: 0-338px; height: 32px} # xia {background-position: 0-376px}

# Comt: hover {background-position:-31px-338px} # shang: hover {background-position:-31px-308px} # xia: hover {background-position: -31px-376px}

/* Archive */

</Style>

/// The internal style is above and there is an external style above. If you do not use an internal style, you can introduce an external style.

<Script type = "text/javascript" src = "http://code.jquery.com/jquery-1.10.1.min.js"> </script>

<Script type = "text/javascript" src = "http://code.jquery.com/jquery-migrate-1.2.1.min.js"> </script>

<Script type = "text/javascript" src = "js/updown/devework. js"> </script>

</Head>

<Body>

<P> 1 </p>

<P> 1 </p>

<P> 1 </p>

<P> 1 </p>

<P> 1 </p>

<P> 1 </p>

<P> 1 </p>

<P> 1 </p>

<P> 1 </p>

<P> 1 </p>

<P> 1 </p>

<P> 1 </p>

<P> 1 </p>

<P> 1 </p>

<P> 1 </p>

<P> 1 </p>

<P> 1 </p>

<P> 1 </p>

<P> 1 </p>

<P> 1 </p>

<P> 1 </p>

<P> 1 </p>

<P> 1 </p>

<P> 1 </p>

<P> 1 </p>

<P> 1 </p>

<P> 1 </p>

<P> 1 </p>

<P> 1 </p>

<P> 1 </p>

<P> 1 </p>

<P> 1 </p>

<P> 1 </p>

<P> 1 </p>

<P> 1 </p>

<P> 333 </p>

<P> 333 </p>

<P> 333 </p>

<P> 333 </p>

<P> 333 </p>

<P> 333 </p>

<P> 333 </p>

<P> 333 </p>

<P> 333 </p>

<P> 333 </p>

<P> 333 </p>

<P> 333 </p>

<P> 333 </p>

<P> 333 </p>

<P> 333 </p>

<P> 333 </p>

<P> 333 </p>

<P> 333 </p>

<P> 333 </p>

<P> 333 </p>

<P> 333 </p>

<P> 333 </p>

<P> 333 </p>

<P> 333 </p>

<P> 333 </p>

<P> 333 </p>

<P> 333 </p>

<P> 333 </p>

<P> 333 </p>

<P> 333 </p>

<P> 333 </p>

<P> 333 </p>

<P> 333 </p>

<P> 333 </p>

<P> 333 </p>

<P> 333 </p>

<P> 333 </p>

<P> 333 </p>

<P> 333 </p>

<P> 333 </p>

<P> 333 </p>

<P> 333 </p>

<P> 333 </p>

<P> 333 </p>

<P> 333 </p>

<P> 333 </p>

<P> 333 </p>

<P> 333 </p>

<P> 333 </p>

<P> 333 </p>

<P> 333 </p>

<P> 333 </p>

<P> 333 </p>

<P> 333 </p>

<P> 333 </p>

<P> 333 </p>

<P> 333 </p>

<P> 333 </p>

<P> 333 </p>

<P> 333 </p>

<P> 333 </p>

<P> 333 </p>

<P> 333 </p>

<Div id = "shangxia">

<Div id = "shang" title = "returns to top"> </div>

<Div id = "comt" title = "the sofa hasn't been snatched yet"> </div>

<Div id = "xia" title = "move to bottom"> </div>

</Div>

</Body>

</Html>

I hope this article will help you with jQuery programming.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.