jQuery实现的支持IE的html滑动条
代码如下:
<html> <script type="text/javascript" src="jquery.js"></script> <style> .d_b{ height: 20px; width: 10px; display: inline-block; background-color: black; position: relative; vertical-align: middle; top: -15px; left: -5px; } </style> <div id="d" style="width:200px;cursor: pointer;" max=100 min=0 value=10 > <div style="height:10px; width:100%; background-color:green" ></div> <b class="d_b"></b> </div> <b id="text"></b> <script> var $dom = $(document); $dom.on('mousedown','#d',function (argument) { $(this).data('mouse','down'); console.log('down'); }) $dom.on('mouseup',function(){ $('#d').data('mouse','up'); console.log('up'); }); $dom.on('mousemove','#d',function(event){ if($(this).data('mouse') == 'down'){ var m_x = event.clientX; var d_b = $(this).find('.d_b'); m_x = m_x < 8 ? 8 : m_x; m_x = m_x > 208 ? 208: m_x; d_b.css('left',m_x-13); var max = $(this).attr('max'); $(this).attr('value', Math.floor((m_x-8)/200 * max)) console.log($(this).attr('value')); $('#text').text($(this).attr('value')) } }); </script> </html>
效果图:
以上就是本文的全部内容了,希望能够对大家学习使用jQuery有所帮助。
相关推荐
EdwardSiCong 2020-11-23
85477104 2020-11-17
hhanbj 2020-11-17
81427005 2020-11-11
seoppt 2020-09-13
honeyth 2020-09-13
WRITEFORSHARE 2020-09-13
84483065 2020-09-11
momode 2020-09-11
85477104 2020-08-15
83510998 2020-08-08
82550495 2020-08-03
tthappyer 2020-08-03
84901334 2020-07-28
tthappyer 2020-07-25
TONIYH 2020-07-22
tztzyzyz 2020-07-20
83510998 2020-07-18
81463166 2020-07-17