Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Web Design (WordPress, Joomla, etc.) Jquery – Image following mouse on a pivot/axel

  • Jquery – Image following mouse on a pivot/axel

    Posted by Letizia Margo on August 21, 2011 at 6:14 am

    Hi, I tried looking around for a javascript that can do this with no luck so far…

    Basically for a website designed for the art of survival information I want to make a navigation in the shape of a compass (all around the inner ring) and have the compass needle follow the mouse whenever it’s on the page.

    I saw a lot of scripts that allows something to follow mouse, but not one that suits my need, because the compass needle need to be anchored at the middle.

    Do you think this is possible? Thank you.

    Letizia Margo replied 14 years, 9 months ago 2 Members · 3 Replies
  • 3 Replies
  • Curtis Thompson

    August 22, 2011 at 12:47 am

    hello…

    like this?

    https://metatroid.com/articles/CSS3%20transforms%20-%20rotate%20image%20with%20mouse

    you’d just have to make your compass bg and then do an overlay of some sort of arrow image and then rotate that like that example, i’d think…

    sitruc

  • Letizia Margo

    August 22, 2011 at 5:11 am

    Yes! That’s it!! Thanks for your help 😀

  • Letizia Margo

    August 23, 2011 at 1:12 am

    I tried following the instructions in that link but it wouldn’t rotate… Did I do it wrong? Is there anything else I should be adding in the code other than this? I added a link to jquery just in case but it still wouldn’t work.

    $(document).ready(function() {

    var img = $('.image');
    if(img.length > 0){
    var offset = img.offset();
    function mouse(evt){
    var center_x = (offset.left) + (img.width()/2);
    var center_y = (offset.top) + (img.height()/2);
    var mouse_x = evt.pageX; var mouse_y = evt.pageY;
    var radians = Math.atan2(mouse_x - center_x, mouse_y - center_y);
    var degree = (radians * (180 / Math.PI) * -1) + 90;
    img.css('-moz-transform', 'rotate('+degree+'deg)');
    img.css('-webkit-transform', 'rotate('+degree+'deg)');
    img.css('-o-transform', 'rotate('+degree+'deg)');
    img.css('-ms-transform', 'rotate('+degree+'deg)');
    }
    $(document).mousemove(mouse);
    }
    });

    Thank you.

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy