ホームページ ウェブフロントエンド jsチュートリアル js+cssでselect_javascriptスキルの美化効果を実現

js+cssでselect_javascriptスキルの美化効果を実現

May 16, 2016 pm 03:08 PM
css js

美化後のレンダリングをお見せします:

CSS:

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

.div-select

{

  border: solid 1px #999;

  height: 40px;

  line-height: 40px;

  cursor: default;

}

 

.div-select-text

{

  float: left;

  background-color: #fff;

  height: 100%;

  word-break: keep-all;

  overflow: hidden;

  cursor: default;

}

 

  .div-select-text > div

  {

    padding: 3px;

    line-height: 34px;

  }

 

.div-select-arrow

{

  background-color: #fff;

  float: right;

  width: 40px;

  height: 100%;

  color: #999;

  cursor: default;

}

 

  .div-select-arrow > div

  {

    border: solid 1px #999;

    margin: 2px;

    height: 34px;

    background-color: #f2f2f2;

    text-align: center;

    line-height: 34px;

    font-size: 22px;

  }

 

.div-select-list

{

  position: absolute;

  float: left;

  top: 100px;

  left: 100px;

  border: solid 1px #999;

  max-height: 300px;

  overflow: auto;

  background-color: #9f9;

  display: none;

  z-index: 9100;

}

 

  .div-select-list .div-select-item:nth-child(2n+1)

  {

    background-color: #fff;

  }

 

.div-select-item

{

  height: 50px;

  line-height: 50px;

  padding-left: 3px;

  padding-right: 3px;

  background-color: #f2f2f2;

  word-break: keep-all;

  overflow: hidden;

  cursor: default;

}

 

.div-select-item-hover

{

  background-color: #3399ff!important;

}

 

.div-select-selected

{

  background-color: #3399ff !important;

}

ログイン後にコピー

JS:

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

//select美化

var divSelectListIndex = 0;

 

$(function () {

  initDivSelect();

});

 

//初始化select美化插件

function initDivSelect() {

  $(".div-select-target").each(function () {

    divSelectListIndex++;

    var select = $(this);

 

    if (select.css("display") == "none") {

      return;

    }

    else {

      select.css("display", "none")

    }

 

    if (select.next("div").find(".div-select-list").length == 0) {

      select.after('<div><div class="div-select"><div class="div-select-text"><div></div></div><div class="div-select-arrow"><div>∨</div></div></div></div>');

      $("body").append('<div class="div-select-list div-select-list-' + divSelectListIndex + '"></div>');

    }

 

    var div = select.next("div");

    var divText = div.find(".div-select-text");

    var divSelect = div.find(".div-select");

    var divArrow = div.find(".div-select-arrow");

    var list = $(".div-select-list-" + divSelectListIndex);

 

    function updateText(item) {

      divText.find("div").html(item.html());

    }

 

    select.find("option").each(function () {

      var option = $(this);

      var text = option.html();

      var value = option.attr("value");

      list.append('<div class="div-select-item" value="' + value + '">' + text + '</div>');

      list.find(".div-select-item:last").click(function () {

        var item = $(this);

        var value = item.attr("value");

        select.val(value);

        select.change();

        list.find(".div-select-selected").removeClass("div-select-selected");

        item.addClass("div-select-selected");

        updateText(item);

        list.hide();

      });

 

      list.find(".div-select-item:last").mouseenter(function () {

        var item = $(this);

        var selectedMark = list.find(".div-select-selected");

        selectedMark.removeClass("div-select-selected");

        selectedMark.addClass("div-select-selected-mark");

        list.find(".div-select-item-hover").removeClass("div-select-item-hover");

        item.addClass("div-select-item-hover");

        updateText(item);

      });

    });

 

    list.mouseleave(function () {

      var selectedMark = list.find(".div-select-selected-mark");

      if (list.find(".div-select-selected").length == 0) {

        selectedMark.addClass("div-select-selected");

        updateText(selectedMark);

      }

      selectedMark.removeClass("div-select-selected-mark");

      list.find(".div-select-item-hover").removeClass("div-select-item-hover");

    });

 

    if (select.attr("width")) {

      divSelect.width(select.attr("width") - 2);

      divText.width(divSelect.width() - divArrow.width());

      if (select.attr("width") > list.width()) {

        list.width(divSelect.width());

      }

    }

 

    div.keydown(function (e) {

      list.find(".div-select-selected-mark").removeClass("div-select-selected-mark");

      list.find(".div-select-item-hover").addClass("div-select-selected");

      list.find(".div-select-item-hover").removeClass("div-select-item-hover");

      if (e.keyCode == 40) {

        var currentSelected = list.find(".div-select-selected");

        var nextSelected = currentSelected.next(".div-select-item");

        if (nextSelected.length == 0) {

          nextSelected = list.find(".div-select-item:first");

          nextSelected.addClass("div-select-selected");

          currentSelected.removeClass("div-select-selected");

          list.scrollTop(0);

        } else {

          nextSelected.addClass("div-select-selected");

          currentSelected.removeClass("div-select-selected");

          var i = 0;

          while (nextSelected.position().top < 0

            || nextSelected.position().top > list.height() - nextSelected.height()) {

            list.scrollTop(list.scrollTop() + nextSelected.height());

            if (i++ > 100) break;

          }

        }

        updateText(nextSelected);

        return false;

      }

      if (e.keyCode == 38) {

        var currentSelected = list.find(".div-select-selected");

        var nextSelected = currentSelected.prev(".div-select-item");

        if (nextSelected.length == 0) {

          nextSelected = list.find(".div-select-item:last");

          nextSelected.addClass("div-select-selected");

          currentSelected.removeClass("div-select-selected");

          list.scrollTop(list.find(".div-select-item").length * nextSelected.height());

        }

        else {

          nextSelected.addClass("div-select-selected");

          currentSelected.removeClass("div-select-selected");

          var i = 0;

          while (nextSelected.position().top < 0

            || nextSelected.position().top > list.height() - nextSelected.height()) {

            list.scrollTop(list.scrollTop() - nextSelected.height());

            if (i++ > 100) break;

          }

        }

        updateText(nextSelected);

        return false;

      }

      if (e.keyCode == 13) {

        var selectedItem = list.find(".div-select-selected");

        var value = selectedItem.attr("value");

        select.val(value);

        list.hide();

        select.change();

      }

    });

 

    divSelect.click(function () {

      $("a").bind("click", function () {

        $("a").unbind("click");

        list.hide();

      });

 

      if (list.css("display") == "none") {

        list.show();

      }

      else {

        list.hide();

      }

 

      list.css("top", divSelect.offset().top + divSelect.height() + 1);

      list.css("left", divSelect.offset().left);

      if ($(window).scrollTop() + $(window).height() < list.offset().top + list.height() + 2) {

        list.css("top", $(window).scrollTop() + $(window).height() - list.height() - 2);

      }

      if (list.width() < divSelect.width()) {

        list.width(divSelect.width());

      }

 

      var currentSelected = list.find(".div-select-selected");

      if (currentSelected.position().top > list.height() - currentSelected.height()) {

        list.scrollTop(currentSelected.position().top - currentSelected.height() * 2);

      }

      return false;

    });

 

    $("html,body").bind("click", function () {

      list.hide();

    });

    list.click(function () {

      return false;

    });

 

    function initSelect() {

      list.find(".div-select-selected").removeClass("div-select-selected");

      var matchItem = list.find(".div-select-item[value='" + select.val() + "']");

      if (matchItem.length > 0) {

        matchItem.addClass("div-select-selected");

        updateText(matchItem);

      }

    }

    initSelect();

    select.change(function () {

      initSelect();

    });

  }); // $(".div-select-target").each

}

ログイン後にコピー

2. 使用方法:

ステップ 1、CSS と JS を引用します:

1

2

3

<link type="text/css" href="~/Scripts/DivSelect/divSelect.css" rel="stylesheet" />

<script type="text/javascript" src="~/Scripts/jquery-1.7.1.min.js"></script>

<script type="text/javascript" src="~/Scripts/DivSelect/divSelect.js"></script>

ログイン後にコピー

ステップ 2、class="div-select-target" width="200" を選択コントロールに追加します。ここで、class="div-select-target" は必須で、width="200" はオプションです。完全な HTML コードは次のとおりです:

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

<link type="text/css" href="~/Scripts/DivSelect/divSelect.css" rel="stylesheet" />

<script type="text/javascript" src="~/Scripts/jquery-1.7.1.min.js"></script>

<script type="text/javascript" src="~/Scripts/DivSelect/divSelect.js"></script>

 

<div style="border: solid 1px #f99; margin: 50px; padding: 50px;">

  <select name="sel" class="div-select-target" width="200" >

    <option value="1">中国</option>

    <option value="2">美国</option>

    <option value="3">法国</option>

    <option value="4">英国</option>

    <option value="5">俄罗斯</option>

    <option value="6">德国</option>

    <option value="7">韩国</option>

    <option value="8">日本</option>

    <option value="9">印度</option>

    <option value="10">巴西</option>

    <option value="11">意大利</option>

    <option value="12">这个国家的名称很长很长很长很长很长很长很长很长</option>

    <option value="13">瑞士</option>

    <option value="14">越南</option>

    <option value="15">缅甸</option>

    <option value="16">泰国</option>

    <option value="17">加拿大</option>

    <option value="18" selected="selected">南非</option>

    <option value="19">澳大利亚</option>

    <option value="20">新西兰</option>

    <option value="21">挪威</option>

    <option value="22">巴勒斯坦</option>

    <option value="23">以色列</option>

    <option value="24">新加坡</option>

    <option value="25">马来西亚</option>

    <option value="26">波兰</option>

    <option value="27">国家27</option>

    <option value="28">国家28</option>

    <option value="29">国家29</option>

    <option value="30">国家30</option>

    <option value="31">国家31</option>

    <option value="32">国家32</option>

    <option value="33">国家33</option>

    <option value="34">国家34</option>

    <option value="35">国家35</option>

    <option value="36">国家36</option>

    <option value="37">国家37</option>

    <option value="38">国家38</option>

  </select>

</div>

<div style="border: solid 1px #f99; margin: 50px; padding: 50px; margin-top: 700px; margin-bottom: 700px;">

  <select name="sel" class="div-select-target" width="200" >

    <option value="1">中国</option>

    <option value="2">美国</option>

    <option value="3">法国</option>

    <option value="4">英国</option>

    <option value="5">俄罗斯</option>

    <option value="6" selected="selected">德国</option>

    <option value="7">韩国</option>

    <option value="8">日本</option>

  </select>

</div>

ログイン後にコピー

2. スクロールバーの美化バージョン:

CSS:

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

.div-select

{

  border: solid 1px #999;

  height: 40px;

  line-height: 40px;

  cursor: default;

}

 

.div-select-text

{

  float: left;

  background-color: #fff;

  height: 100%;

  word-break: keep-all;

  overflow: hidden;

  cursor: default;

  font-size: 16px;

  font-family: 微软雅黑,雅黑;

}

 

  .div-select-text > div

  {

    padding: 3px;

    line-height: 34px;

  }

 

.div-select-arrow

{

  background-color: #fff;

  float: right;

  width: 40px;

  height: 100%;

  color: #999;

  cursor: default;

}

 

  .div-select-arrow > div

  {

    border: solid 1px #999;

    margin: 2px;

    height: 34px;

    background-color: #f2f2f2;

    text-align: center;

    line-height: 34px;

    font-size: 22px;

  }

 

.div-select-list

{

  position: absolute;

  float: left;

  top: 100px;

  left: 100px;

  border: solid 1px #999;

  max-height: 300px;

  overflow: hidden;

  background-color: #9f9;

  display: none;

  z-index: 9100;

  font-size: 16px;

  font-family: 微软雅黑,雅黑;

}

 

  .div-select-list .div-select-item:nth-child(2n+1)

  {

    background-color: #fff;

  }

 

.div-select-item

{

  height: 50px;

  line-height: 50px;

  padding-left: 3px;

  padding-right: 3px;

  background-color: #f2f2f2;

  word-break: keep-all;

  overflow: hidden;

  cursor: default;

}

 

.div-select-item-hover

{

  background-color: #3399ff!important;

}

 

.div-select-selected

{

  background-color: #3399ff !important;

}

 

.div-select-list-scrollbar

{

  position: absolute;

  float: left;

  border: solid 1px #999;

  border-left: 0;

  background-color: #e8e8ec;

  width: 40px;

  height: 300px;

  display: none;

  cursor: default;

  z-index: 9101;

}

 

.div-select-scrollbar-up

{

  border-bottom: solid 1px #fff;

  height: 39px;

  font-size: 22px;

  line-height: 39px;

  color: #999;

  background-color: #cdcdcd;

  text-align: center;

}

 

.div-select-scrollbar-pos

{

  height: 220px;

}

 

  .div-select-scrollbar-pos > div:last-child

  {

    width: 40px;

    height: 20px;

    background-color: #cdcdcd;

  }

 

.div-select-scrollbar-down

{

  border-top: solid 1px #fff;

  height: 39px;

  font-size: 22px;

  line-height: 39px;

  color: #999;

  background-color: #cdcdcd;

  text-align: center;

}

ログイン後にコピー

JS:

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

263

264

265

//select美化

var divSelectListIndex = 0;

 

$(function () {

  initDivSelect();

});

 

//初始化select美化插件

function initDivSelect() {

  $(".div-select-target").each(function () {

    divSelectListIndex++;

    var select = $(this);

 

    if (select.css("display") == "none") {

      return;

    }

    else {

      select.css("display", "none")

    }

 

    if (select.next("div").find(".div-select-list").length == 0) {

      select.after('<div><div class="div-select"><div class="div-select-text"><div></div></div><div class="div-select-arrow"><div>∨</div></div></div></div>');

      $("body").append('<div class="div-select-list div-select-list-' + divSelectListIndex + '"></div>');

    }

 

    var div = select.next("div");

    var divText = div.find(".div-select-text");

    var divSelect = div.find(".div-select");

    var divArrow = div.find(".div-select-arrow");

    var list = $(".div-select-list-" + divSelectListIndex);

    var scrollbar;

    var scrollbarPosTop;

    var scrollbarPos;

    var scrollbarScrollHeight;

    var scrollbarUp;

    var scrollbarDown;

    var itemHeight;

    var itemCount;

    var itemsHeight;

    var scrollFlag = false;

 

    function updateText(item) {

      divText.find("div").html(item.html());

    }

 

    select.find("option").each(function () {

      var option = $(this);

      var text = option.html();

      var value = option.attr("value");

      list.append('<div class="div-select-item" value="' + value + '">' + text + '</div>');

      list.find(".div-select-item:last").click(function () {

        var item = $(this);

        var value = item.attr("value");

        select.val(value);

        select.change();

        list.find(".div-select-selected").removeClass("div-select-selected");

        item.addClass("div-select-selected");

        updateText(item);

        list.hide();

        if (scrollbar) scrollbar.hide();

      });

 

      list.find(".div-select-item:last").mouseenter(function () {

        var item = $(this);

        var selectedMark = list.find(".div-select-selected");

        selectedMark.removeClass("div-select-selected");

        selectedMark.addClass("div-select-selected-mark");

        list.find(".div-select-item-hover").removeClass("div-select-item-hover");

        item.addClass("div-select-item-hover");

        updateText(item);

      });

    });

 

    list.mouseleave(function () {

      var selectedMark = list.find(".div-select-selected-mark");

      if (list.find(".div-select-selected").length == 0) {

        selectedMark.addClass("div-select-selected");

        updateText(selectedMark);

      }

      selectedMark.removeClass("div-select-selected-mark");

      list.find(".div-select-item-hover").removeClass("div-select-item-hover");

    });

 

    if (select.attr("width")) {

      divSelect.width(select.attr("width") - 2);

      divText.width(divSelect.width() - divArrow.width());

    }

    else {

      divText.width(list.width());

    }

 

    div.keydown(function (e) {

      list.find(".div-select-selected-mark").removeClass("div-select-selected-mark");

      list.find(".div-select-item-hover").addClass("div-select-selected");

      list.find(".div-select-item-hover").removeClass("div-select-item-hover");

      if (e.keyCode == 40) {

        var currentSelected = list.find(".div-select-selected");

        var nextSelected = currentSelected.next(".div-select-item");

        if (nextSelected.length == 0) {

          nextSelected = list.find(".div-select-item:first");

          nextSelected.addClass("div-select-selected");

          currentSelected.removeClass("div-select-selected");

          list.scrollTop(0);

        } else {

          nextSelected.addClass("div-select-selected");

          currentSelected.removeClass("div-select-selected");

          var i = 0;

          while (nextSelected.position().top < 0

            || nextSelected.position().top > list.height() - nextSelected.height()) {

            list.scrollTop(list.scrollTop() + nextSelected.height());

            if (i++ > 100) break;

          }

        }

        updateText(nextSelected);

        updateScrollbarPos();

        return false;

      }

      if (e.keyCode == 38) {

        var currentSelected = list.find(".div-select-selected");

        var nextSelected = currentSelected.prev(".div-select-item");

        if (nextSelected.length == 0) {

          nextSelected = list.find(".div-select-item:last");

          nextSelected.addClass("div-select-selected");

          currentSelected.removeClass("div-select-selected");

          list.scrollTop(list.find(".div-select-item").length * nextSelected.height());

        }

        else {

          nextSelected.addClass("div-select-selected");

          currentSelected.removeClass("div-select-selected");

          var i = 0;

          while (nextSelected.position().top < 0

            || nextSelected.position().top > list.height() - nextSelected.height()) {

            list.scrollTop(list.scrollTop() - nextSelected.height());

            if (i++ > 100) break;

          }

        }

        updateText(nextSelected);

        updateScrollbarPos();

        return false;

      }

      if (e.keyCode == 13) {

        var selectedItem = list.find(".div-select-selected");

        var value = selectedItem.attr("value");

        select.val(value);

        list.hide();

        if (scrollbar) scrollbar.hide();

        select.change();

      }

    });

 

    itemHeight = list.find(".div-select-item:first").height();

    itemCount = list.find(".div-select-item").length;

    itemsHeight = itemHeight * itemCount;

    if (itemsHeight > list.height()) {

      $("body").append('<div class="div-select-list-scrollbar div-select-list-scrollbar-' + divSelectListIndex + '"><div class="div-select-scrollbar-up">∧</div><div class="div-select-scrollbar-pos"><div></div><div></div></div><div class="div-select-scrollbar-down">∨</div></div>');

    }

    scrollbar = $(".div-select-list-scrollbar-" + divSelectListIndex);

    scrollbarPosTop = scrollbar.find(".div-select-scrollbar-pos").find("div:first");

    scrollbarPos = scrollbar.find(".div-select-scrollbar-pos").find("div:last");

    scrollbarScrollHeight = scrollbarPos.parent().height() - scrollbarPos.height();

    scrollbarUp = scrollbar.find(".div-select-scrollbar-up");

    scrollbarDown = scrollbar.find(".div-select-scrollbar-down");

    scrollbar.click(function () {

      return false;

    });

    scrollbarUp.click(function () {

      list.scrollTop(list.scrollTop() - list.height());

      updateScrollbarPos();

    });

    scrollbarDown.click(function () {

      list.scrollTop(list.scrollTop() + list.height());

      updateScrollbarPos();

    });

    scrollbar.mousedown(function () {

      scrollFlag = true;

    });

    scrollbar.mouseup(function () {

      scrollFlag = false;

    });

    scrollbar.mousemove(function (e) {

      if (scrollFlag) {

        var pos = e.pageY - scrollbar.offset().top - 50;

        if (pos <= scrollbarScrollHeight) {

          scrollbarPosTop.height(pos);

          list.scrollTop(scrollbarPosTop.height() / scrollbarScrollHeight * (itemsHeight - list.height()));

        }

      }

    });

 

    function updateScrollbarPos() {

      scrollbarPosTop.height(scrollbarScrollHeight * list.scrollTop() * 1.0 / (itemsHeight - list.height()));

      if (list.scrollTop() + list.height() == itemsHeight) {

        scrollbarPosTop.height(scrollbarScrollHeight);

      }

    }

 

    divSelect.click(function () {

      $("a").bind("click", function () {

        $("a").unbind("click");

        list.hide();

        scrollbar.hide();

      });

 

      if (list.css("display") == "none") {

        list.show();

        scrollbar.show();

      }

      else {

        list.hide();

        scrollbar.hide();

      }

 

      list.css("top", divSelect.offset().top + divSelect.height() + 1);

      list.css("left", divSelect.offset().left);

      var listOffsetTop = list.offset().top;

      if ($(window).scrollTop() + $(window).height() < list.offset().top + list.height() + 2) {

        list.css("top", $(window).scrollTop() + $(window).height() - list.height() - 2);

      }

      if (list.width() < divSelect.width()) {

        if (!(itemsHeight > list.height())) {

          list.width(divSelect.width());

        }

        else {

          list.width(divSelect.width() - scrollbar.width());

        }

      }

 

      scrollbar.find(".div-select-scrollbar-pos").find("div:first").height(0);

      scrollbar.css("left", divSelect.offset().left + list.width() + 1);

      scrollbar.css("top", divSelect.offset().top + divSelect.height() + 1);

      if ($(window).scrollTop() + $(window).height() < listOffsetTop + list.height() + 2) {

        scrollbar.css("top", $(window).scrollTop() + $(window).height() - list.height() - 2);

      }

 

      var currentSelected = list.find(".div-select-selected");

      if (currentSelected.position().top > list.height() - currentSelected.height()) {

        list.scrollTop(currentSelected.position().top - currentSelected.height() * 2);

      }

      updateScrollbarPos();

 

      return false;

    });

 

    $("html,body").bind("click", function () {

      list.hide();

      scrollbar.hide();

    });

    list.click(function () {

      return false;

    });

 

    function initSelect() {

      list.find(".div-select-selected").removeClass("div-select-selected");

      var matchItem = list.find(".div-select-item[value='" + select.val() + "']");

      if (matchItem.length > 0) {

        matchItem.addClass("div-select-selected");

        updateText(matchItem);

      }

    }

    initSelect();

    select.change(function () {

      initSelect();

    });

  }); // $(".div-select-target").each

}

ログイン後にコピー

レンダリング:

以上がこの記事の全内容です。JavaScript プログラミングを学習する皆さんのお役に立てれば幸いです。

このウェブサイトの声明
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。

ホットAIツール

Undresser.AI Undress

Undresser.AI Undress

リアルなヌード写真を作成する AI 搭載アプリ

AI Clothes Remover

AI Clothes Remover

写真から衣服を削除するオンライン AI ツール。

Undress AI Tool

Undress AI Tool

脱衣画像を無料で

Clothoff.io

Clothoff.io

AI衣類リムーバー

Video Face Swap

Video Face Swap

完全無料の AI 顔交換ツールを使用して、あらゆるビデオの顔を簡単に交換できます。

ホットツール

メモ帳++7.3.1

メモ帳++7.3.1

使いやすく無料のコードエディター

SublimeText3 中国語版

SublimeText3 中国語版

中国語版、とても使いやすい

ゼンドスタジオ 13.0.1

ゼンドスタジオ 13.0.1

強力な PHP 統合開発環境

ドリームウィーバー CS6

ドリームウィーバー CS6

ビジュアル Web 開発ツール

SublimeText3 Mac版

SublimeText3 Mac版

神レベルのコード編集ソフト(SublimeText3)

VueでBootstrapの使用方法 VueでBootstrapの使用方法 Apr 07, 2025 pm 11:33 PM

vue.jsでBootstrapを使用すると、5つのステップに分かれています。ブートストラップをインストールします。 main.jsにブートストラップをインポートしますブートストラップコンポーネントをテンプレートで直接使用します。オプション:カスタムスタイル。オプション:プラグインを使用します。

HTML、CSS、およびJavaScriptの役割:コアの責任 HTML、CSS、およびJavaScriptの役割:コアの責任 Apr 08, 2025 pm 07:05 PM

HTMLはWeb構造を定義し、CSSはスタイルとレイアウトを担当し、JavaScriptは動的な相互作用を提供します。 3人はWeb開発で職務を遂行し、共同でカラフルなWebサイトを構築します。

ブートストラップにスプリットラインを書く方法 ブートストラップにスプリットラインを書く方法 Apr 07, 2025 pm 03:12 PM

ブートストラップスプリットラインを作成するには2つの方法があります。タグを使用して、水平方向のスプリットラインを作成します。 CSS Borderプロパティを使用して、カスタムスタイルのスプリットラインを作成します。

HTML、CSS、およびJavaScriptの理解:初心者向けガイド HTML、CSS、およびJavaScriptの理解:初心者向けガイド Apr 12, 2025 am 12:02 AM

webdevelopmentReliesOnhtml、css、andjavascript:1)htmlStructuresContent、2)cssStylesit、および3)Javascriptaddsinteractivity、形成、

ブートストラップに写真を挿入する方法 ブートストラップに写真を挿入する方法 Apr 07, 2025 pm 03:30 PM

ブートストラップに画像を挿入する方法はいくつかあります。HTMLIMGタグを使用して、画像を直接挿入します。ブートストラップ画像コンポーネントを使用すると、レスポンシブ画像とより多くのスタイルを提供できます。画像サイズを設定し、IMG-Fluidクラスを使用して画像を適応可能にします。 IMGボーダークラスを使用して、境界線を設定します。丸い角を設定し、IMGラウンドクラスを使用します。影を設定し、影のクラスを使用します。 CSSスタイルを使用して、画像をサイズ変更して配置します。背景画像を使用して、背景イメージCSSプロパティを使用します。

ブートストラップボタンの使用方法 ブートストラップボタンの使用方法 Apr 07, 2025 pm 03:09 PM

ブートストラップボタンの使用方法は?ブートストラップCSSを導入してボタン要素を作成し、ブートストラップボタンクラスを追加してボタンテキストを追加します

ブートストラップのフレームワークをセットアップする方法 ブートストラップのフレームワークをセットアップする方法 Apr 07, 2025 pm 03:27 PM

Bootstrapフレームワークをセットアップするには、次の手順に従う必要があります。1。CDNを介してブートストラップファイルを参照してください。 2。独自のサーバーでファイルをダウンロードしてホストします。 3。HTMLにブートストラップファイルを含めます。 4.必要に応じてSASS/LESSをコンパイルします。 5。カスタムファイルをインポートします(オプション)。セットアップが完了したら、Bootstrapのグリッドシステム、コンポーネント、スタイルを使用して、レスポンシブWebサイトとアプリケーションを作成できます。

ブートストラップのサイズを変更する方法 ブートストラップのサイズを変更する方法 Apr 07, 2025 pm 03:18 PM

Bootstrapの要素のサイズを調整するには、次のものを含むDimensionクラスを使用できます。

See all articles