Home > Web Front-end > JS Tutorial > Simulating Apple-style scroll bar_drop-down menu implemented using JTrackBar

Simulating Apple-style scroll bar_drop-down menu implemented using JTrackBar

WBOY
Release: 2016-05-16 19:11:01
Original
1423 people have browsed it

Copy code The code is as follows:

function JObj(){}
JObj.$c = function(tag){return document.createElement(tag)};
JObj.$ = function(id){return document.getElementById(id)};
JObj.isRate = function(pRateString){
    if(!isNaN(pRateString)) return false;
    if(pRateString.substr(pRateString.length-1,1) != "%")
        return false;
    if(isNaN(pRateString.substring(0,pRateString.length - 1)))
        return false;
    return true;
}

function JPos(){}
JPos.getAbsPos = function(pTarget){
    var x_ = y_ = 0;
    while(pTarget.offsetParent){
            x_  = pTarget.offsetLeft;
            y_  = pTarget.offsetTop;
            pTarget = pTarget.offsetParent;
    }
    x_  = pTarget.offsetLeft;
    y_  = pTarget.offsetTop;
    return {x:x_,y:y_};
}

JPos.getMousePos = function(evt){
    var x_ = y_ = 0;
    evt = evt || window.event;
    if(evt.pageX || evt.pageY){
        x_ = evt.pageX;
        y_ = evt.pageY;
    }else{
        x_ = evt.clientX   document.body.scrollLeft - document.body.clientLeft;
        y_ = evt.clientY   document.body.scrollTop - document.body.clientTop;
    }

    return {x:x_,y:y_};        
}