最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Ruler on web page - Stack Overflow

programmeradmin0浏览0评论

I want something like top and left ruler as we have in word that depicts mouse position on ruler, do we have anything in-build on jquery/is there any way to achieve this??

Any UI pro please respond for the same

I want something like top and left ruler as we have in word that depicts mouse position on ruler, do we have anything in-build on jquery/is there any way to achieve this??

Any UI pro please respond for the same

Share Improve this question edited Jul 18, 2011 at 3:43 Varun asked Jun 10, 2011 at 5:10 VarunVarun 5,05112 gold badges56 silver badges86 bronze badges 0
Add a ment  | 

3 Answers 3

Reset to default 5

Ignoring the creation of the ruler elements, say you had a little div inside each ruler that showed the position of the mouse on the relevant axis, with IDs of mouse-x-pos and mouse-y-pos, respectively, you could do:

$(document).ready(function() {
    $('body').mousemove(function(event) {
        $('#mouse-x-pos').css('left', event.pageX + 'px');
        $('#mouse-y-pos').css('top', event.pageY + 'px');
    });
});

I'll leave the CSS to you, the main thing is to use the mousemove function with jQuery.

Heres I plugin I wrote which doesn't require Jquery or anything else. https://github./MrFrankel/ruler

You can try jquery-ui.ruler. It is a jquery-ui plugin that creates a top and left ruler.

Features:

  • units (px, mm, cm, in)
  • rules in sub-div's
  • ticks spacing/visibility is customizable
  • mouse track

Example:

// simple initialization
$('.selector').ruler();

// or use different unit and tick values
$('.selector').ruler({
    unit: 'mm',
    tickMajor: 10,
    tickMinor: 5,
    tickMicro: 1,
    showLabel: true
});
发布评论

评论列表(0)

  1. 暂无评论