开发者

get the pixel width of an element and convert to number

How to get the width of an element. Convert it to percentages (%). An reset the element width +1. I like the jplayer volume be also controlled by the mouse weel. Problem is to get the pixel width as a number(integer).

.jp-volume-bar-value sets it width in %, but开发者_如何转开发 jquery get it in px and so must be converted to % (ratio 1.66).

To use parseInt on var loud does't seem to work (is get an different number). Who can help?

      $('#volume-hold').bind('mousewheel', function(event, delta) {
        var loud =  $('.jp-volume-bar-value').css('width');
        var load = loud * 1.666666; //max px / 100
        var dir = delta > 0 ? 'Up' : 'Down',
            vel = Math.abs(delta);
        if (dir === 'Up') {
             var loud = loud + 1;
             $('.jp-volume-bar-value').css('width', '('+loud+')');
        }else{

        }            
        return false;
    });


It's possible that parseInt isn't working because you're not setting the base. try:

var result = parseInt(loud * 1.666, 10); //sets parseInt to base 10

Also, you may want to ensure that the value you're getting back from jQuery is a number:

var width = Number($('#element').css('width'));

then you can try to parseInt it

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜