Home > Web Front-end > HTML Tutorial > Example showing DIV+CSS implementation of radio station list

Example showing DIV+CSS implementation of radio station list

巴扎黑
Release: 2017-09-02 09:57:32
Original
2076 people have browsed it

This article mainly introduces the sample code of p+CSS to implement radio station list design. The editor thinks it is quite good, so I will share it with you now and give it as a reference. Let’s follow the editor and take a look

CSS Spite technology: that is, CSS sprite technology. In fact, CSS sprites are icon elements in pictures. These icons can make buttons, labels, logos, etc. . This technology has been applied to many websites, which can effectively reduce the number of transmission requests. The required icons are summarized in one image, and can be applied to the entire page once downloaded

The following examples are mainly the application of CSS wizard technology. Direct Po code:


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

239

240

241

242

243

244

245

246

247

248

249

250

251

252

253

254

255

256

257

258

259

260

261

262

<!DOCTYPE html>

<html>

<head>

    <meta charset="utf-8">

    <title>酷狗电台列表设计</title>

    <style>

        #frm{

            margin:0;

            padding:0;

            list-style-type: none;

            width: 500px;

            border:1px solid #000;

            overflow: hidden;

        }

        #frm *{

            margin:0;

            padding: 0;

            font-size: 12px;

        }

        #frm li{

            padding:4px 0;

            width: 47%;

            float: left;

            margin:5px 15px 5px 0;

            cursor: pointer;

        }

        #frm li span{

            color:#999;

            position: relative;

        }

        #frm li .d{

            width: 38px;

            height: 38px;

            float: left;

            margin:0px 12px 6px 0;

            background-image: url(img/spite2.jpg);

            position: relative;

        }

        #frm li .cont{

            position: relative;

            height: 37px;

            overflow: hidden;

        }

        .cont p{

            margin:5px 0 5px 0;

        }

        .d p{

            position: absolute;

            width: 100%;

            height: 100%;

        }

        .d .img,.d .play{

            background-image: url(img/spite2.jpg);

        }

        .l1 .d .img{

            background-position: 38px 0;

        }

        .l2 .d .img{

            background-position: 76px 0;

        }

        .l3 .d .img{

            background-position: 114px 0;

        }

        .l4 .d .img{

            background-position: 152px 0;

        }

        .l5 .d .img{

            background-position: 190px 0;

        }

        .l6 .d .img{

            background-position: 228px 0;

        }

        .l7 .d .img{

            background-position: 266px 0;

        }

        .l8 .d .img{

            background-position: 304px 0;

        }

        .l9 .d .img{

            background-position: 342px 0;

        }

        .ll .d .img{

            background-position: 380px 0;

        }

        .d .mask,.d .play{

            visibility: hidden;

        }

        .choose .d{

            background-position: 38px 0;

            outline: 1px solid rgb(233,243,250);

        }

        .choose .d .mask{

            background-color: #000;

            filter:alpha(Opacity=50);

            opacity: 0.5;

            height: 32px;

            width: 32px;

            top:3px;

            left: 3px;

            visibility: visible;

        }

        .choose .d .play{

            background-position: 418px 0;

            visibility: visible;

        }

        .choose .cont p{

            font-weight: bold;

            color:rgb(0,155,250);

        }

    </style>

    <script>

        function mouseoverhandle(obj){

            obj.className += &#39; choose&#39;;

        }

        function mouseouthandle(obj){

            obj.className = obj.className.substring(0,2);

        }

    </script>

</head>

<body>

<ul id="frm">

    <li class="l1" onmouseover="mouseoverhandle(this)" onmouseout="mouseouthandle(this)">

        <p class="d">

            <p class="img"></p>

            <p class="mask"></p>

            <p class="play"></p>

        </p>

        <p class="cont">

            <p>酷狗热歌</p>

            <span href="#">徐朗 - 小夜曲</span>

        </p>

    </li>

    <li class="l2" onmouseover="mouseoverhandle(this)" onmouseout="mouseouthandle(this)">

        <p class="d">

            <p class="img"></p>

            <p class="mask"></p>

            <p class="play"></p>

        </p>

        <p class="cont">

            <p>DJ热碟</p>

            <span href="#">曾春年 - 最幸福的人</span>

        </p>

    </li>

    <li class="l3" onmouseover="mouseoverhandle(this)" onmouseout="mouseouthandle(this)">

        <p class="d">

            <p class="img"></p>

            <p class="mask"></p>

            <p class="play"></p>

        </p>

        <p class="cont">

            <p>网络红歌</p>

            <span href="#">徐志强 - 想你的时候</span>

        </p>

    </li>

    <li class="l4" onmouseover="mouseoverhandle(this)" onmouseout="mouseouthandle(this)">

        <p class="d">

            <p class="img"></p>

            <p class="mask"></p>

            <p class="play"></p>

        </p>

        <p class="cont">

            <p>新歌</p>

            <span href="#">孙俪 - 美丽信号</span>

        </p>

    </li>

    <li class="l5" onmouseover="mouseoverhandle(this)" onmouseout="mouseouthandle(this)">

        <p class="d">

            <p class="img"></p>

            <p class="mask"></p>

            <p class="play"></p>

        </p>

        <p class="cont">

            <p>经典</p>

            <span href="#">游鸿明 - 寻你</span>

        </p>

    </li>

    <li class="l6" onmouseover="mouseoverhandle(this)" onmouseout="mouseouthandle(this)">

        <p class="d">

            <p class="img"></p>

            <p class="mask"></p>

            <p class="play"></p>

        </p>

        <p class="cont">

            <p>怀旧粤语</p>

            <span href="#">陈慧娴 - 人生何处不相逢</span>

        </p>

    </li>

    <li class="l7" onmouseover="mouseoverhandle(this)" onmouseout="mouseouthandle(this)">

        <p class="d">

            <p class="img"></p>

            <p class="mask"></p>

            <p class="play"></p>

        </p>

        <p class="cont">

            <p>钢琴</p>

            <span href="#">July - My Soul</span>

        </p>

    </li>

    <li class="l8" onmouseover="mouseoverhandle(this)" onmouseout="mouseouthandle(this)">

        <p class="d">

            <p class="img"></p>

            <p class="mask"></p>

            <p class="play"></p>

        </p>

        <p class="cont">

            <p>KTV必点</p>

            <span href="#">蔡健雅 - 无底洞</span>

        </p>

    </li>

    <li class="l9" onmouseover="mouseoverhandle(this)" onmouseout="mouseouthandle(this)">

        <p class="d">

            <p class="img"></p>

            <p class="mask"></p>

            <p class="play"></p>

        </p>

        <p class="cont">

            <p>思念</p>

            <span href="#">张杰 - 这就是爱</span>

        </p>

    </li>

    <li class="ll" onmouseover="mouseoverhandle(this)" onmouseout="mouseouthandle(this)">

        <p class="d">

            <p class="img"></p>

            <p class="mask"></p>

            <p class="play"></p>

        </p>

        <p class="cont">

            <p>DJ外文舞曲</p>

            <span href="#">Jean Cloud Ades</span>

        </p>

    </li>

</ul>

<script>

    var ul = document.getElementById(&#39;frm&#39;);

    var li = document.getElementsByTagName(&#39;li&#39;);

    var spans;

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

        spans = li[i].getElementsByTagName(&#39;span&#39;);

        li[i].span_obj = spans[0];

    }

    var index = -1;

    function showup(){

        if(li[index].span_obj.style.top == &#39;&#39;){

            li[index].span_obj.style.top = &#39;13px&#39;;

        }

        if(parseInt(li[index].span_obj.style.top)<=0){

            li[index].span_obj.style.top = &#39;&#39;;

            setTimeout(&#39;shownext()&#39;,1000);

        }else{

            li[index].span_obj.style.top = parseInt(li[index].span_obj.style.top)-1 +&#39;px&#39;;

            setTimeout(&#39;showup()&#39;,100);

        }

    }

    function shownext(){

        index++;

        index = index%li.length;

        showup();

    }

    setTimeout(shownext,1000);

</script>

</body>

</html>

Copy after login

Generation effect:

## Code analysis:

1.ul tag contains 10 li tags inside. Because the icon of each li tag is a different sub-picture, different class attributes are added to each li tag.

2. The p tag whose class attribute is d for each li tag contains three p tags. Their class attributes are img, mask and play. These three tags are theme icon, mask in turn. icon and play icon, and their parent node p (class attribute is d) has a background image as a border.

3. Each li tag has added onmouseover and onmouseout event response letters.

4. The last piece of js code is to simulate the effect of the song name rising when the music box switches songs.

First, the program obtains the tag with the id of frm, and obtains all li sub-tags of the tag. At the same time, it obtains all li span tags, and binds the first span tag to span_obj of the li tag object.

Two timeout functions: showext() and showup(). The showup() function is responsible for producing the song title raising effect, and the function showext() is responsible for switching to the playback of the song on the next music station.

The method of an object cannot set itself as a timeout function

The above is the detailed content of Example showing DIV+CSS implementation of radio station list. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
css
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template